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!

Regular Expressions Ride Again 2

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Greetings,

I'm finally making a bold attempt at learning regular expressions. I've been reviewing the following:

When learning pattern searching it states:
Criteria: /[abcde]/ will match any single lowercase vowel.
Question: last I checked, b c and d were not vowles, so why would that match any lowercase vowel?

Further, it states
Criteria: /[^a-e]in]/

?An institute has posted guidance that protects against a reported vulnerability in all versions of software that could allow a Web site visitor to view secured content by using specially crafted requests to a Web server?.
[/quote]
Questions:
A. programming has taught me that every opening breacket must have a closing and vice versa. Does this not apply to regular expressions?
B. how does the s fall in between a-e?

Thanks for help on these.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Hi

acent said:
last I checked, b c and d were not vowles, so why would that match any lowercase vowel?
Of course, that will match any of the enumerated characters.
the article you are referring to said:
Posted: 25 May 2005
Please lower your expectations when reading old articles. ;-) Such ugliness happens especially with technical articles to become malformed due to careless rewriting of the site and batch modification of the texts.

I used to read the perlre. While the PHP documentation recommends the use of PCRE ( Perl-Compatible Regular Expressions ), most of that article is useful for PHP developers too. Not sure if it is suitable for your level. ( The perlrequick and perlretut tutorials and the perlfaq6 FAQ are also about regular expressions. )

Feherke.
 
so why would that match any lowercase vowel?

it won't. the author is a monkey. this is the regex for vowel matching
Code:
$pattern = '/[aeiouy]/';

take or leave the 'y' as you see fit.

to your questions

A. there is no need to close a bracket if you are trying to match only the opening bracket. however, programmatically, all brackets must be closed when used other than in their literal sense in a regex.

B. the pattern is matching every letter that is NOT a, b, c, d, e and that is immediately followed by the letters 'in' (case sensitive. therefore the sin of using will be matched. In this case the author is correct :
Negation in this context refers to everything not included in the listed character set is matched.
 
Thank you feherke for the pointers to better tutorials.

Thanks jpadie for the clarifications. Yes, the author did state about the negation and for some reason I just didn't get it.

Thanks again!

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top