Regular expression to split the string in Characters


#1

Hello There,

Can anyone tell me that if i have to split the string in individual characters (not on behalf of any delimiter) then what regular expression do i have to use?

For Ex: If have a string “Prashant” then expected output should be :-

P
R
A
S
H
A
N
T

Since, i am bound to use the regular expression so I would to know that specific regular expression.
Your help will be really appreciated.

Regards,
Prashant Srivastava


#2

Assuming you are using any programming language, you could just loop the string using for loop, so it would look like:

print c for c in phrase

In case it is Python 3, you can do it like this:

[print(c) for c in "Foobar"]
# Output
F
o
o
b
a
r

Could be Ruby too:

puts "Foobar".chars
# Output
F
o
o
b
a
r

#3

Hi,

Thanks for the reply. Actually, I am not using any programming language, I am working in Oracle dB and there I have to use regular expression rather than using for loop and iterate values.

Normally, in languages like c# , Java it’s quite simple we don’t have to use the regular expression for such cases. But, here in dB regular expression will perform better in case of running it in on millions of records. Else,we can come across performance issue.

Regards,
Prashant Srivastava