Boopathi
(Boopathi Manogar)
January 11, 2020, 11:52am
1
Hi friends,
want to replace one single character in a string using regex. Could anyone help on this?
E.g Mark S Twain==> S to be replaced as string.empty and result to be “Mark Twain”
J Mark Tailor ==> Again J to be replaced as string.empty and result to be “Mark Tailor”
Thanks,
Ula
1 Like
Hi
Hope this expression would help you resolve this
If this string is in a variable of type string named strinput
Then for specific to this string input
Stroutput = System.Text.RegularExpressions.Regex.Replace(strinput.ToString,”( S )”,” ”).ToString
Or for general string input with this kind character in between or atlast
Stroutput = System.Text.RegularExpressions.Regex.Replace(strinput.ToString,”\s[A-Z]{1,3}\s”).ToString
Cheers
Yoichi
(Yoichi)
January 11, 2020, 12:13pm
3
Hi,
Can you try the following expression?
System.Text.RegularExpressions.Regex.Replace(strData,"(^[A-Z] )|((?<= )[A-Z] )","")
Regards,
2 Likes
Boopathi
(Boopathi Manogar)
January 12, 2020, 3:38am
4
Hi @Yoichi
It is not highlighting any single letter character.
Thanks
Boopathi
(Boopathi Manogar)
January 12, 2020, 3:44am
5
Hi @Palaniyappan
Thank you. It is not highlighting any single character. Could you please check and help me on this?
Regular exp need to highlight any single character in a group of words
h kjlkdf werwer - only h to highlighted using regex and then i replace it with string.empty
iuoiuower piupwer k - only k to be highlighted and replaced.
uouoewr r oopoiwer - only r to be highlighted and replaced.
Thanks
1 Like
If the single character is always capital and followed by a space, you can use the following regular expression. Please mention if you have any other specific requirement.
[A-Z]{1}(\s)
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
1 Like
Awesome got it same expression but with only one correction
This worked perfect as per your requirement When I tried to simulate
Kindly have a view on this
Cheers @Boopathi
Yoichi
(Yoichi)
January 12, 2020, 5:16am
8
Hi,
If you want to remove not only upper case but also lower case, please use [A-Za-z] instead of [A-Z].
Regards,
system
(system)
Closed
January 15, 2020, 5:17am
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.