Detect space between Hyphen

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

@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…

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…

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

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”

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

@Abhishek_Changan
have a look here, handling also some variations
grafik

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…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.