Hi,
I’m trying to identify string if it contains space between word and hyphen.
ex.: “Indian Institute of Technology - Bombay.” this is incorrect.
“Indian Institute of Technology-Bombay.” this is correct.
Please help me with this…
Thanks in advance…
1 Like
ppr
(Peter Preuss)
July 13, 2020, 6:23am
2
@Abhishek_Changan
The simple approach is using replace
YourStringVar.replace(" - “,”-")
For more variations a regex replace is suggested
1 Like
But I don’t want it to be replaced, just detection is required…
ppr
(Peter Preuss)
July 13, 2020, 6:27am
4
Then Go for regex ismatch Activity or regex Match Activity and Count the occurence to detect If the Case ist präsent or not
1 Like
Can you please elaborate how to use this in UiPath…
ppr
(Peter Preuss)
July 13, 2020, 6:35am
6
Yes give me some little time, Otherwise go to regex101.com and Play with this pattern ( - ). Once you have found a working pattern use the isregex Activity with found pattern and you will get a boolean result If IT was found or not
1 Like
SamanGuruge
(Palliya Guruge Saman Priyalal)
July 13, 2020, 6:52am
7
Hi @Abhishek_Changan ,
Use following regex
Regex.isMatch(yourString,“(?<=-)(\s{1})|(?=-)(\s{1})” )
1 Like
Hey @SamanGuruge ,
Good regex…
It checks for space after the hyphen, i.e. “Hello- Hello”.
Can you modify it to check for sides, i.e. “Hello -Hello”
SamanGuruge
(Palliya Guruge Saman Priyalal)
July 13, 2020, 7:01am
9
so sorry I was created for both way but I did some mistake in the patten after OR i’m checking the leading space now it’s ok
Regex.isMatch(yourString,“(?<=-)(\s{1})|(\s{1})(?=-)” )
2 Likes
ppr
(Peter Preuss)
July 13, 2020, 7:42am
10
@Abhishek_Changan
have a look here, handling also some variations
2 Likes
Hi
To validate whether it has space along the sides of “-”
we can do it with simple assign activity
like this
bool_exists = System.Text.RegularExpressions.Regex.IsMatch(“your input string”,“( - )”)
where bool_exits is a boolean variable which will give True OR False based on the presence of space along side.
Cheers @Abhishek_Changan
3 Likes
@Abhishek_Changan Use below regex System.Text.RegularExpressions.Regex.IsMatch(variable1,“[a-zA-z\s]+[-][a-zA-Z]+.*”)
Sequence1 - Copy.xaml (4.7 KB)
1 Like
Thanks for this, helped me to get the answer I expected…
1 Like
Hi @ppr ,
Thanks for this link, learned a lot…
system
(system)
Closed
July 18, 2020, 10:49am
15
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.