Copy link to clipboard
Copied
Hi ,
I need to fetch a particular value from a string,
eg:
input :
abc def def test|test2|test3
my required output should be:
test|test2|test3
How to go about this using any function or any other alternate solution.
Kindly advice !!!
ok, so we probably need to use a regular expression then. Something like this perhaps:
Find: ^[^ ]*? [^ ]*? [^ ]*? (.*)$
Replace with: \1
This worked for me:
<cfset yourString = "abc def def test|test2|test3">
<cfoutput>
#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#
</cfoutput>
<br />
<cfset yourString = "abc def def test|test 2|test3">
<cfoutput>
#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#
</cfoutput>
Copy link to clipboard
Copied
Your requirements are a little bit unclear. But it seems to me that you just want to get the bit at the end of the string, following the last space? You could just use listLast(), specifying a space as the delimiter.
<cfset yourString = "abc def def test|test2|test3">
<cfoutput>
#listLast(yourString, " ")#
</cfoutput>
Copy link to clipboard
Copied
hi
actually my requirement is to exclude the string values till first three spaces and print the remaining.
ie.
input :
abc def def test|test2|test3
i need to exclude "abc def def" and print the remaning test|test2|test3
but listLast will not work for some cases like
input :
abc def def test|test 2|test3
this prints
2|test3
Copy link to clipboard
Copied
ok, so we probably need to use a regular expression then. Something like this perhaps:
Find: ^[^ ]*? [^ ]*? [^ ]*? (.*)$
Replace with: \1
This worked for me:
<cfset yourString = "abc def def test|test2|test3">
<cfoutput>
#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#
</cfoutput>
<br />
<cfset yourString = "abc def def test|test 2|test3">
<cfoutput>
#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#
</cfoutput>
Copy link to clipboard
Copied
Thanks It worked !!!