Jump to content

Recommended Posts

Posted

Hi,

I don't understand why this expression is not lazy:

$path = "some\path\that\annoys"
ConsoleWrite(StringRegExpReplace($path, "\\.+?$", "", 0) & @CRLF)

I'm trying to delete just "annoys" but the regexp matches "paththatannoys"  :ermm:

Posted

Because like humanity it's greedy. Use (?U).

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Don't listen to the guy in post #2 (he's stupid!)...try this...

$path = "some\path\that\annoys"
ConsoleWrite(StringRegExpReplace($path, "\\[^\\]*$", "") & @CRLF)
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Here my version:

ConsoleWrite(StringRegExpReplace($path, "(.+)\\.*", "\1") & @CRLF)

@guinness: your regex will fail to remove last <word> when <word> is empty.

 

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
  On 4/22/2014 at 6:21 PM, UEZ said:

@guinness: your regex will fail to remove last <word> when <word> is empty.

Fixed it! Though in all honesty I was only providing what the OP suggested.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

  On 4/22/2014 at 5:40 PM, j0kky said:

Hi,

I don't understand why this expression is not lazy:

 

Cruel people, providing solutions without answering the question...  :)

".+?$" : the regex engine finds the first antislash, then returns the shortest match up to the end (lazy or not lazy don't matter) because the dot in .+?  matches everything including the next antislashes

That's why guinNess solution [^]* is the good one (matching everything EXCEPT antislash)

Edit

(unpardonable typo)

Edited by mikell
Posted
  On 4/22/2014 at 8:50 PM, mikell said:

That's why guinNess solution [^]* is the good one (matching everything EXCEPT antislash)

Brilliant!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...