Jump to content
Ketarin forum

Backslash in regex


B@T
 Share

Recommended Posts

I tried to make a regular expression with a backslash in it. For example: {file:regex:[^\\].*$} should return the filename from a filepath. But if i put the backslash in the regular expression, it returns an empty string.

Edited by B@T
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

I tried 3 backslashes as CybTekSol suggested, but it's not working too.

 

floele, well, it's a perfect workaround, but i think in the bugs topic, we prefer concentrate on the problem which demonstrated by the example.

 

Oh, and i tried some other regexp patterns, and i also can't use colon in it, because Ketarin thinks, it's a separator, and i can't escape it with backslash(es).

Link to comment
Share on other sites

B@T, I think you're using a flawed assumption. My understanding was that from a variable with a value like this "c:\user\me\stuff\files.txt" you were trying to return only "files.txt". By default, Regex isn't multiline, so an exclusion ([^\\]) wouldn't return anything if your variable had a carriage return or line feed within it. Consider passing it thru a "trim" before you attempt the regex grab. Or, alternatively, use optional carriage return/line feeds as possible terminators in the grab:

{file:regex:[^\\]+[\r\n\s\t]*$}

Link to comment
Share on other sites

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
 Share

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