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
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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.