Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question regards regexep

Status
Not open for further replies.

shlomyb

Programmer
Nov 14, 2006
32
IL
I have this regexe :
$line =~ m!<?xml\s+version="([^"]+)"\s+encoding="([^"]+)"?\s+>!


Why I can not catch this line ?!

<?xml version="1.0" encoding="iso-8859-1"? >
 
Got it sorry...

$line =~ m!<[\s]*\?[\s]*xml[\s]*version="([^"]+)"[\s]*encoding="([^"]+)"[\s]*\?[\s]*>!)
 
Yes, '?' is a special character and must be escaped.
 
There's no need to put square brackets around \s.

Using square brackets creates a "character class", which means that it can match any one of a number of characters. \s is already a character class by itself, so you'd only put it in square brackets if you want to add other characters to the class (for example if you wanted to matches spaces or underscores, you'd use [\s_]).

So to match multiple whitespace, just use \s*
 
ishnid

I didn't know you could use classes like \n and \S inside the square brackets of a character class?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Dont ask me why but I tried the \s* and it did NOT work so I tried other possibilities and one of them was to use [\s]*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top