forum-msg-id-130360-edit

Original date:2016-09-18 13:16:40 Edited by: jessedavis Subject: regex observation & question regarding re:escape()

Windows 7 pro sp1 euphoria: 4.0.5 (362497032f33, 2012-10-11)

I guess I am missing something here. I don't see what it is.

From the manual ==> 8.20.6.1 escape()

 Escape special regular expression characters that may be entered into a search string from user input. 
Notes: 
Special regex characters are:  
 
. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -   
 
Example 1: 
 
include std/regex.e as re 
sequence search_s = re:escape("Payroll is $***15.00") 
-- search_s = "Payroll is \\$\\*\\*\\*15\\.00" 


What is actually produced by the above eucode is:

"Payroll is \$\*\*\*15\.00" which will not compile as a eu regex

another special character (from above list) is the backslash.
escape() cannot deal with it at all giving an unknown escaped character error..
So, use the alternative entry method offered in the docs: use #/.../ instead of "..." as an example: regex will not compile the following:
regex p = re:new(#/\*/)
from the docs:
The alternative writing style lets you write a regex without doubling up on the escape characters: 
 
regex sample = re:new( #/\*/ ) 

Giving the error message: hex number not formed correctly.
Using a double escape does still work.
Regular expressions are hairy enough without all the extra backslashes.
iN ANY EVENT, THE DOCS SOULD AGREE WITH THE PERFORMANCE!

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu