In my database some keywords are surrounded by the “/” and “\” characters.
On the application end, in ColdFusion, I am trying to extract and separate text that appears in and either before or after a string of text surrounded by the “/” and “\”
So say I have a sentence: My baloney has a first name and it is /HOMER\
- I want to separate the two so I have one variable that has the string My baloney has a first name and it is
- and another variable that has HOMER without the “/” and “\”
Again, the “/” and “\” can appear before or after a string of text, as shown below:
/Ash\ Gotta catch’em all
.
/Nike\ Just do it.
.
Impossible is nothing. /Adidas\
.
Microsoft is already facing lawsuits related to the just-launched Windows, with an operating system technology designer accusing Microsoft of ripping of its patent for “tiles.”
SurfCast, in a complaint filed yesterday in a U.S. District Court in Maine, said Microsoft infringes one of its four patents — No. 6,724,403 — by “making, using, selling, and offering to sell devices and software products” covered by SurfCast’s patent. That includes mobile devices using the Windows Phone 7 and Windows Phone 8 operating systems as well as PCs using /Windows 8\
How can I extract and separate text that appears in and either before or after a string of text surrounded by the “/” and “\” ?
If the separate text is always at the start/end you can simply use ListFirst like so:
And you’ll have both parts in separate variables. To work out which is which, you’ll want to do a
Left(Text,1)to determine if the original text started with/or not.Otherwise, you can extract the /…\ text with rematch:
Which returns an array of matches starting with
/– you can’t avoid capturing the first slash in CF’s regex (no lookbehind support), but you can remove it afterwards with substring:(Use
1instead ofxif only ever one result, otherwise you’ll need a loop.)To get the text without this value you can can then use a simple replace like so: