- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Regex help -
hello, I need just some help to use Regex function --
String is like --
"Fine.2020.Optional.(Not)"
Required -- "Fine_2020_Optional"
I have tried couple of combination, but not able to get the result in one regex. I am using this type of Regex in my for loop script.
Any help ?
Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
It would probably help if we had more examples of input and expected output and where you are getting hung up. The JSL below works for your single case, but I'm not sure if it's applicable to all of your data in general.
Regex("Fine.2020.Optional.(Not)",
"(\w+?)\.(\d+?)\.(\w+?)\.\(\w+?\)",
"\1_\2_\3"
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
It would probably help if we had more examples of input and expected output and where you are getting hung up. The JSL below works for your single case, but I'm not sure if it's applicable to all of your data in general.
Regex("Fine.2020.Optional.(Not)",
"(\w+?)\.(\d+?)\.(\w+?)\.\(\w+?\)",
"\1_\2_\3"
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
There few simpler one, I was able to do it but this was the one. which gave me some trouble. Next time if I found any issue, I will get back to you with more details. Do you have some reference / link to share with me /us on Regex with good examples ? That would be very helpful.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
This website has some great general information about Regex:
https://www.regular-expressions.info/quickstart.html
There is also a tool for generating a regex based on your inputs and expected outputs:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
Regex( "this.is.jmp", "\.", "_", GLOBALREPLACE );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
OK, so off line I got a couple of comments about the very short solution.
Here's how to get there on you own. It might be cheating, but it's soooooo much easier.
I made a table with the example in it. Selected the column and used recode.
In Recode I used replace string, and turned on the regular expressions.
In the recode dialog I turned on both scripting options (bottom right)
Then saved the script to the script window, copied the little bit and pasted it here. (well, verified it worked and then pasted it.)
Huge thanks to @ErnestPasour : )
oh, and there is that little bit using "\." rather than "." alone. The backslash is an escape character, and keeps from replacing everything with "_". That's the only bit of regex knowledge needed to make this work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
Don't forget the built-in JMP functions for doing string manipulation, like Substitute(), Munger() and, my favorite, Word(). The syntax for those might be easier to deal with for something like this.
str="Fine.2020.Optional.(Not)";
show(substitute(str, ".", "_"));
show(word(1, str, ".") || "_" || word(2, str, ".") || "_" || word(3, str, "."));
show(concat items(words(str, ".")[1::3], "_"));
Log:
Substitute(str, ".", "_") = "Fine_2020_Optional_(Not)"; Word(1, str, ".") || "_" || Word(2, str, ".") || "_" || Word(3, str, ".") = "Fine_2020_Optional"; Concat Items(Words(str, ".")[Index(1, 3)], "_") = "Fine_2020_Optional";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Regex help -
Pattern match, could also be a good solution, but I keep getting tripped up on the syntax. If only there was someone around who was fluent in snbol... @Craige_Hales