Jump to content
Ketarin forum
B@T

Backslash in regex

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

Share this post


Link to post
Share on other sites

I'm not sure how should I try. I tried [^/\]*$ and [^/\/\]*$ but these didn't work. Could you post me an example?

Edited by B@T

Share this post


Link to post
Share on other sites

I think I had the two forward slashes in my previous post confused with two backslashes ( \\ )... Try two backslashes ( \\ ) with EACH backslash you use... in other words... 3 backslashes will make 1 backslash in regex.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
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]*$}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

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