Regular Expressions

  • Thread starter Thread starter norton
  • Start date Start date
N

norton

Hello,

Does any one know how to extact the following text into 4 different
groups(namely Date, Artist, Album and Quality)?
[2005-01] - Artist - Album
[2005-01] Artist - Album
[2005-01] - Artist - Album [123kbps]
[2005-01] - Artist - Album-[123kbps]

i have try this syntax but it failed
\[?<Date>[^\]]*\]\s-\s(?<Artist>\b)\s-\s(?<Album>[^[]*)

Thx a lot

Regards,
Norton
 
\[(.*)\]\s\-?\s?(\S*)\s\-\s([A-z]*)(\s?\-?\[(.*)\]

<year> = $1
<artist> = $2
<album> = $3
<quality> = $5
 
Sorry, I missed the ')' at the end.

\[(.*)\]\s\-?\s?(\S*)\s\-\s([A-z]*)(\s?\-?\[(.*)\])

mr_patel said:
\[(.*)\]\s\-?\s?(\S*)\s\-\s([A-z]*)(\s?\-?\[(.*)\]

<year> = $1
<artist> = $2
<album> = $3
<quality> = $5

norton said:
Hello,

Does any one know how to extact the following text into 4 different
groups(namely Date, Artist, Album and Quality)?
[2005-01] - Artist - Album
[2005-01] Artist - Album
[2005-01] - Artist - Album [123kbps]
[2005-01] - Artist - Album-[123kbps]

i have try this syntax but it failed
\[?<Date>[^\]]*\]\s-\s(?<Artist>\b)\s-\s(?<Album>[^[]*)

Thx a lot

Regards,
Norton
 
Norton,
In addition to the other suggestions, I would strongly recommend both
Expresso & RegEx Workbench, as they both have wizards of varying degrees to
help you build your expression, plus they allow you to test your
expressions, also the analyzer/interpreter in each is rather handy

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/...pleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A tutorial & reference on using regular expressions:http://www.regular-expressions.info/The MSDN's documentation on regular expressions:http://msdn.microsoft.com/library/d...pconRegularExpressionsLanguageElements.aspFor an example of using Expresso, if you enter the following in the RegularExpression tab:\[(?<Date>\d{4}-\d{2})\]\s*-?\s*(?<Artist>\w*)\s*-?\s*(?<Album>\w*)(\s*-?\s*\[(?<Quality>\w*)\])?Then enter the following, in the Sample Input Data:[2005-01] - Artist - Album[2005-01] Artist - Album[2005-01] - Artist - Album [123kbps][2005-01] - Artist - Album-[123kbps]You can click the Run Match button, the Result of Search and Replace willgive you a tree with your results. It will show one node for each line thatmatched, if you expand a node, it will show you the parameters that matched(in this case Date, Artist, Album & Quality). Then numbered match (1: in thetree) is just a place holder as the entire Quality is optional...As you select nodes in the Results tree, the source is selected in theSample Input Area.Very useful tool!NOTE: The expression is a solution to your question.Hope this helpsJay"norton" <[email protected]> wrote in messagenews:[email protected]...> Hello,>> Does any one know how to extact the following text into 4 different> groups(namely Date, Artist, Album and Quality)?> [2005-01] - Artist - Album> [2005-01] Artist - Album> [2005-01] - Artist - Album [123kbps]> [2005-01] - Artist - Album-[123kbps]>> i have try this syntax but it failed> \[?<Date>[^\]]*\]\s-\s(?<Artist>\b)\s-\s(?<Album>[^[]*)>> Thx a lot>> Regards,> Norton>>
 
Whoa, what happened there?

Here is a (hopefully) properly formatted response!


In addition to the other suggestions, I would strongly recommend both
Expresso & RegEx Workbench, as they both have wizards of varying degrees to
help you build your expression, plus they allow you to test your
expressions, also the analyzer/interpreter in each is rather handy

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/...pleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A

tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/d...l/cpconRegularExpressionsLanguageElements.asp

For an example of using Expresso, if you enter the following in the
RegularExpression tab:

\[(?<Date>\d{4}-\d{2})\]\s*-?\s*(?<Artist>\w*)\s*-?\s*(?<Album>\w*)(\s*-?\s*\[(?<Quality>\w*)\])?

Then enter the following, in the Sample Input Data:

[2005-01] - Artist - Album
[2005-01] Artist - Album
[2005-01] - Artist - Album [123kbps]
[2005-01] - Artist - Album-[123kbps]

You can click the Run Match button, the Result of Search and Replace will
give you a tree with your results. It will show one node for each line that
matched, if you expand a node, it will show you the parameters that matched
(in this case Date, Artist, Album & Quality). The numbered match (1: in the
tree) is just a place holder as the entire Quality is optional... As you
select nodes in the Results tree, the source is selected in the Sample Input
Area.

Very useful tool!

NOTE: The above expression is a solution to your question.

Hope this helps
Jay

Jay B. Harlow said:
Norton,
In addition to the other suggestions, I would strongly recommend both
Expresso & RegEx Workbench, as they both have wizards of varying degrees
to help you build your expression, plus they allow you to test your
expressions, also the analyzer/interpreter in each is rather handy

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/...pleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A
tutorial & reference on using regular
expressions:http://www.regular-expressions.info/The MSDN's documentation
on regular
expressions:http://msdn.microsoft.com/library/d...pconRegularExpressionsLanguageElements.aspFor
an example of using Expresso, if you enter the following in the
RegularExpression
tab:\[(?<Date>\d{4}-\d{2})\]\s*-?\s*(?<Artist>\w*)\s*-?\s*(?<Album>\w*)(\s*-?\s*\[(?<Quality>\w*)\])?Then
enter the following, in the Sample Input Data:[2005-01] - Artist -
Album[2005-01] Artist - Album[2005-01] - Artist - Album
[123kbps][2005-01] - Artist - Album-[123kbps]You can click the Run Match
button, the Result of Search and Replace willgive you a tree with your
results. It will show one node for each line thatmatched, if you expand a
node, it will show you the parameters that matched(in this case Date,
Artist, Album & Quality). Then numbered match (1: in thetree) is just a
place holder as the entire Quality is optional...As you select nodes in
the Results tree, the source is selected in theSample Input Area.Very
useful tool!NOTE: The expression is a solution to your question.Hope this
messageHello,>> Does any
one know how to extact the following text into 4 different> groups(namely
Date, Artist, Album and Quality)?> [2005-01] - Artist - Album> [2005-01]
Artist - Album> [2005-01] - Artist - Album [123kbps]> [2005-01] - Artist -
Album-[123kbps]>> i have try this syntax but it failed>
\[?<Date>[^\]]*\]\s-\s(?<Artist>\b)\s-\s(?<Album>[^[]*)>> Thx a lot>>
Regards,> Norton>>
 
Thx Jay, you ar so nice!

^o^

Regards,
Norotn
Jay B. Harlow said:
Norton,
In addition to the other suggestions, I would strongly recommend both
Expresso & RegEx Workbench, as they both have wizards of varying degrees to
help you build your expression, plus they allow you to test your
expressions, also the analyzer/interpreter in each is rather handy

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/...pleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A
tutorial & reference on using regular
expressions:http://www.regular-expressions.info/The MSDN's documentation on
regular
expressions:http://msdn.microsoft.com/library/default.asp?url=/library/en-us
/cpgenref/html/cpconRegularExpressionsLanguageElements.aspFor an example of
using Expresso, if you enter the following in the RegularExpression
tab:\[(?<Date>\d{4}-\d{2})\]\s*-?\s*(?<Artist>\w*)\s*-?\s*(?<Album>\w*)(\s*-
?\s*\[(?<Quality>\w*)\])?Then enter the following, in the Sample Input
Data:[2005-01] - Artist - Album[2005-01] Artist - Album[2005-01] - Artist -
Album [123kbps][2005-01] - Artist - Album-[123kbps]You can click the Run
Match button, the Result of Search and Replace willgive you a tree with your
results. It will show one node for each line thatmatched, if you expand a
node, it will show you the parameters that matched(in this case Date,
Artist, Album & Quality). Then numbered match (1: in thetree) is just a
place holder as the entire Quality is optional...As you select nodes in the
Results tree, the source is selected in theSample Input Area.Very useful
tool!NOTE: The expression is a solution to your question.Hope this
messageHello,>> Does any one
know how to extact the following text into 4 different> groups(namely Date,
Artist, Album and Quality)?> [2005-01] - Artist - Album> [2005-01] Artist -
Album> [2005-01] - Artist - Album [123kbps]> [2005-01] - Artist -
Album-[123kbps]>> i have try this syntax but it failed>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top