search replace regex help

Post Reply
Arthur
Member
Posts: 113
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

search replace regex help

Post by Arthur »

After spending decent amount of time with the basics of regex I got some bits to work, but still struggling with the following:

Filename Search & Replace

search for : ^\d{1,2}(?=\s)
string: 1 AZ SPOCS _ IP NTF-signed.pdf

so this returns the '1' matching the regex criteria.

Now I would like to add a '.0' after the matched return
So I go: $&.0 (this seems to be PERL Regex flavour compliant)
but it does not work
neither does \2.0 nor $2.0 and so on.

Online validators for regex return positive in either case, that it shall work, showing the result as 1.0 (...).pdf, but Switch simply either replaces the matched string (1) with a .0 and therefore the file is omitted as not supported when starting with a DOT, or simply does nothing leaving it unchanged.

Anyone help me with this pls ??

KR
Arthur
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: search replace regex help

Post by cstevens »

Probably a more elegant way to do this but:

var inputString = "1 AZ SPOCS _ IP NTF-signed.pdf";
inputString = inputString.replace(/^\d{1,2}(?=\s)/, inputString.match(/^\d{1,2}(?=\s)/) + ".0");
Arthur
Member
Posts: 113
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: search replace regex help

Post by Arthur »

Thank you for your prompt answer.
This is great, but how would I use it with 'Rename Job' Action: Search & Replace -> RegEx ?
I do not have scripting module I am afraid :/
Or am I missing sth ...

KR
Arthur
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: search replace regex help

Post by cstevens »

Sorry, I don't know how to do that. You may have better luck if you post this in the Flows forum.
Arthur
Member
Posts: 113
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: search replace regex help

Post by Arthur »

For anyone else struggling with similar case - the regex search phrase has to be in brackets, so that it then can be recalled as \1 and followed by whatever you want to add after it.
In my case \10 does the job :)
NEOSA
Member
Posts: 39
Joined: Thu Mar 10, 2016 6:31 pm

Re: search replace regex help

Post by NEOSA »

Arthur wrote:For anyone else struggling with similar case - the regex search phrase has to be in brackets, so that it then can be recalled as \1 and followed by whatever you want to add after it.
In my case \10 does the job :)
Hi,

I tried with () brackets, but it does not work neither for me :

Search : (^\d{1,2}(?=\s))
Replace by : \10

Any clues
Arthur
Member
Posts: 113
Joined: Sat Sep 09, 2017 11:58 pm
Location: Yateley, UK

Re: search replace regex help

Post by Arthur »

@ NEOSA:
it depends if you are searching the string from the beginning or not.
the ^ might be the clue.
It can also be an exclusion to the search element definition that comes afterwards.
The way that Regex works in Switch is not so obvious as all validators here and there would make you think it shall be.

And my current experience with it shows that 0 instead of being just a digit / sign has some undocumented function, so that when you actually want to input 0 somewhere in the 'replace' definition, it then instead of inputting it, executes some action that the 0 does, although the Regular Expression reference in HELP section does not specify what it is.
So when \10\2 shall add 0 between the match for 1 and 2 respectively, it does not.

I may be wrong, but I have proofs for that.
If you can be more specific about the string you are searching, I may be of more help with the RegEx.
Post Reply