Posts: 1,339
Threads: 101
Joined: Apr 2025
I've used regex very little and I'm having trouble figuring this one out.
With the following two, I'd like either the full string, or the part following the '::' if it exists
"Location"
"Inspections_Selected::Inspector"
would return
"Location"
"Inspector"
TIA
Posts: 5,314
Threads: 111
Joined: May 2025
In other words, you want to strip out everything from the beginning of the line through the '::' (if it exists) and output the remainder of the line.
sed -E 's/^.*:://'
will do this. In the Terminal, try:
$ (echo Location ; echo Inspections_Selected::Inspector) | sed -E 's/^.*:://'
Location
Inspector
$
Posts: 1,339
Threads: 101
Joined: Apr 2025
Posts: 1,339
Threads: 101
Joined: Apr 2025
wow, thanks guys.
TheCaber, perfect! thanks a bunch.
Seacrest, that site will come in handy - ty
Posts: 1,339
Threads: 101
Joined: Apr 2025
TheCaber, would this do the same thing?
\b\w+(?!

\b
Posts: 5,314
Threads: 111
Joined: May 2025
Um, you never specified
which language you were using to code the regular expressions. I gave the 'old school' UNIX/POSIX sed (stream editor) BRE (basic regular expressions) form.
Your latest post is clearly 'new school'. According to
http://www.greenend.org.uk/rjk/2002/06/regexp.html , it is one of Perl, Python or Tcl, since it involves negated 'lookahead'. I'll guess it is Perl.
\b (match boundary at beginning of word)
\w+ (match one or more word-class characters (alphanumeric or underscore))
( ? ! : ) (next character is not a colon) (I embedded spaces to hold off the smilies)
\b (match boundary at end of word)
I think this will not eat the second colon, nor will it deal with embedded spaces or other non-word-class characters.
FWIW,
Posts: 5,314
Threads: 111
Joined: May 2025
Here's one way to do it in Perl (there are many ways, most superior to this).
In the Terminal:
(First be sure we're in the Bourne shell, not csh or bash)
% sh
sh-3.2$
sh-3.2$ ( echo Location ; echo Inspections_Selected::Inspector ) | perl -e 'while ( <> ) {; print if s/(?:\b\w+::\b)?(.*)$/$1/; };'
Location
Inspector
sh-3.2$
Ugly. Sorry.
Posts: 1,339
Threads: 101
Joined: Apr 2025
Sorry I should have been more specific.
Yes, I failed to mention what language this was in. Truth be told, I'm in over my head anyway

. I did know what sed was though (I have a buddy who's a Unix guru).
As it turns out, I may not be able to do this anyway. I was trying to use regex inside an xslt file. I'm trying to transform an xml file into an fdf file for a pdf form. I want the fdf field name to take on the name attribute of the xml field element, but I don't want to include the table portion of said name. This is all new to me, but I feel I'm very close to a solution - in fact, I have it working if I hard code the field names, but I don't feel that's very wise (in case the xml is formed different than expected).