Jump to content

[SOLVED] using * in regex


programguru

Recommended Posts

I am and really stumped, and I wanted to know if anyone could shed some light on my misunderstanding.

 

Using the * in a match - of course * means zero or more of the previous char

 

If sama*ntha

 

matches: sammntha, samantha, and samaaantha

 

why would it not match smantha ??

 

Can anyone explain this? I cannot find a sensible answer online and it driving me nuts!

Link to comment
https://forums.phpfreaks.com/topic/109685-solved-using-in-regex/
Share on other sites

So it appears to be matching everything literal after and before "a" but obviously "a" does not need to exist, so "smantha" would evaluate to false.

 

So the correct explanation of * would be "looking for exact strings prior and after the previous char marked with *"

 

Like:

 

john*na

 

johnona would return true

johnnnna would return true

jonnna would return false

 

Am I getting this or dreaming?

 

 

So the correct explanation of * would be "looking for exact strings prior and after the previous char marked with *"

 

Quantifier applies only to what is immediately in front of it, which could be either character, (non-)capturing parentheses, character class.

lordfrikk,

 

That makes sense, but I am not sure why would "sama*ntha" evaluate true for "sammntha"? As you can see "sama" is no part of it. TravisJRyan seemed to clarify this, but am I missing something?

 

I tried expr "sama*ntha" on this test case "sammntha"

 

no matches

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.