Home regexprep function not able to accept \b to find number range
Reply: 0

regexprep function not able to accept \b to find number range

user922
1#
user922 Published in May 27, 2018, 3:36 am

I am attempting to use regular expression substitution for the following types of strings:

'y = 0'
'y = 10'
'y = 23'

I want the replacement to return the number only if it lies between 1 and 22. (i.e. less than 1 and greater than 22 will return some other result)

I have it written as follows, and I cannot understand why this won't work:

regexprep('y = 5', 'y = '\b([1-9]$|1[0-9]|2[0-2])\b', '$1')

Is there something I am missing about syntax here? I find that if I remove the \b I can get the proper result for:

regexprep('y = 0', 'y = ([1-9]|1[0-9]|2[0-2])', '$1')

i.e. no change, and for the numbers from 1-22 I get the right result, but then all numbers greater than 22 are also getting replaced by $1 as well. I have no idea why. Any help would be great. Thanks.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322761 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO