max, min for substring length not working?

A swapping-ground for Regular Expression syntax

max, min for substring length not working?

Postby deselby » Tue Aug 08, 2017 1:55 pm

I have a filename like 'mushy 1234567 fruit.cat' and want to remove the digits but only if the substring is >= 3 and <= 10 long. For the example filename

Match: (.*)[0-9]{3,10}(.*)
Replace: \1\2

doesn't work but

Match: (.*)[0-9]{7}(.*)
Replace: \1\2

does. I have tested the {min, max} qualifier as in the example with other regex engines and it works.
deselby
 
Posts: 2
Joined: Tue Aug 08, 2017 1:17 pm

Re: max, min for substring length not working?

Postby therube » Fri Aug 11, 2017 4:47 pm

Either it is the way the particular RegEx library works, or we (myself included) are not understanding the regex code as written?
https://postimg.org/image/g5d21re7v/
https://postimg.org/image/6yureh8zf/

I get the same results (with mushy cat) here,http://www.den4b.com/tools/regex.
Code: Select all
   Find: (.*)[0-9]{3,10}(.*)
Replace: $1-------$2

  Input: mushy 1234567 fruit.cat
Output: mushy 1234------- fruit.cat
http://www.regular-expressions.info/repeat.html
Last edited by therube on Sat Aug 12, 2017 2:54 pm, edited 2 times in total.
therube
 
Posts: 392
Joined: Mon Jan 18, 2016 6:23 pm

Re: max, min for substring length not working?

Postby Panchdara » Fri Aug 11, 2017 10:05 pm

Sorry therube I reported your pics as inappropriate - your picture host was displaying, what I initially deemed inappropriate adverts that shadowed your images. posting org definitely imposes their images over the one(s) you intended.
Panchdara
 
Posts: 32
Joined: Sat Jan 09, 2016 7:25 pm

Re: max, min for substring length not working?

Postby deselby » Sat Aug 12, 2017 2:17 pm

Solved - my problem. All for the lack of a space between ) and [.

Match: (.*)[0-9]{3,10}(.*) - wrong
Match: (.*) [0-9]{3,10}(.*) - right

For 'mushy 1234567 fruit.cat' this yields 'mushy fruit.cat' whereas 'mushy 12 fruit.cat' is not affected and remains as 'mushy 12 fruit.cat'. Which is what I wanted :D Cheers.
deselby
 
Posts: 2
Joined: Tue Aug 08, 2017 1:17 pm

Re: max, min for substring length not working?

Postby therube » Sat Aug 12, 2017 2:51 pm

See if these are any better:

https://s25.postimg.org/uok7367cv/BRU_mushy_fruit_cat-1.png
https://s25.postimg.org/j0q58mi7z/BRU_mushy_fruit_cat-2.png
therube
 
Posts: 392
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions