Regular match and grouping

Here's an example of the line I want has a regex on

101-nocola_conte_-_fuoco_fatuo_(koop_remix) 

The first digit in "101" is the disc number, and the next two digits are the track numbers. How to match track numbers and ignore disc number (first digit)?

+1
regex
Jan 15 '09 at 9:20
source share
4 answers

You mean that you don't like the disc number, but you want to combine, say, track number 01?

In perl, you would match it like this: "^ [0-9] 01. *"
or just "^ .01. *" - this means that you don’t even mind if the first char is not a digit.

+1
Jan 15 '09 at 9:28
source share

Something like

 /^\d(\d\d)/ 

Compare one digit at the beginning of the line, then write down the next two digits

+3
Jan 15 '09 at 9:25
source share
 ^\d(\d\d) 

You may need \ before ( depending on which environment you are going to run the regular expression in (for example, vi(1) ).

+1
Jan 15 '09 at 9:25
source share

What programming language? For the shell, something with egrep will do the job:

 echo '101-nocola_conte_-_fuoco_fatuo_(koop_remix)' | egrep -o '^[0-9]{3}' | egrep -o '[0-9]{2}$' 
0
Jan 15 '09 at 9:30
source share



All Articles