|
Posted by ikeon on November 27, 2008, 3:40 am
Please log in for more thread options
Hi All,
I have a script that I convert xml tags to html. like "<" I convert to
"<" and so on.
after the conversion I need to capture the information inside the tag.
let take for example the string "<abcd>: which is equivalent to
show/hide quoted text
"<abcd>".
I tried to capture the "abcd" which can be different from tag to tag
in the following way:
/\<\;([^\&\gt\;]*)/
like match "<" and then match anything that is not ">".
the thing is that it doesn't work on all tags for some reason and I
was wondering on a principal base if doing a [^somestring] suppose to
work ?
Thanks.
|
|
Posted by Peter Makholm on November 27, 2008, 3:50 am
Please log in for more thread options
show/hide quoted text
> like match "<" and then match anything that is not ">".
> the thing is that it doesn't work on all tags for some reason and I
> was wondering on a principal base if doing a [^somestring] suppose to
> work ?
No, using [^string] wont work as you're expecting. Just like
[string] doesn't match 'string' but only one of the letters s, t, r,
i, n, or g [^stirng] just matches one letter which isn't in 'string'.
What you need is a negative look-ahead (?!string). Read 'perldoc
perlre' for the explanation of it.
//Makholm
|
|
Posted by John W. Krahn on November 27, 2008, 5:13 am
Please log in for more thread options ikeon wrote:
show/hide quoted text
>
> I have a script that I convert xml tags to html. like "<" I convert to
> "<" and so on.
> after the conversion I need to capture the information inside the tag.
> let take for example the string "<abcd>: which is equivalent to
> "<abcd>".
> I tried to capture the "abcd" which can be different from tag to tag
> in the following way:
>
> /\<\;([^\&\gt\;]*)/
You probably want something like:
/<(.*?)>/
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
|
|
Posted by ikeon on November 27, 2008, 1:30 pm
Please log in for more thread options show/hide quoted text
> ikeon wrote:
> > I have a script that I convert xml tags to html. like "<" I convert to
> > "<" and so on.
> > after the conversion I need to capture the information inside the tag.
> > let take for example the string "<abcd>: which is equivalent to
> > "<abcd>".
> > I tried to capture the "abcd" which can be different from tag to tag
> > in the following way:
> > /\<\;([^\&\gt\;]*)/
> You probably want something like:
> /<(.*?)>/
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0--=
Larry Wall
The (?!string) didn't work for some reason but I have learned a lot
from "perldoc perlre" ;)
The solution was /<(.*?)>/ which is the simple one. I tried it
with only (.*) but it was "greedy".
Thanks John and Peter for your quick respone.
|
|
Posted by sln on November 28, 2008, 1:38 pm
Please log in for more thread options
show/hide quoted text
>Hi All,
>I have a script that I convert xml tags to html. like "<" I convert to
>"<" and so on.
>after the conversion I need to capture the information inside the tag.
>let take for example the string "<abcd>: which is equivalent to
>"<abcd>".
>I tried to capture the "abcd" which can be different from tag to tag
>in the following way:
>/\<\;([^\&\gt\;]*)/
>like match "<" and then match anything that is not ">".
>the thing is that it doesn't work on all tags for some reason and I
>was wondering on a principal base if doing a [^somestring] suppose to
>work ?
>Thanks.
I'm still confused with your terminology 'xml tags to html'.
So be it.
show/hide quoted text
How do you go from "<abcd>" to "<abcd>" without capturing
'abcd' ?
sln
|
| Similar Threads | Posted | | need to negate regex in middle of expression | June 20, 2005, 6:19 am |
| Multi-Match (to Array) Regex with a precodition match? | August 5, 2007, 2:43 pm |
| RegEx Help, Please? (match after n) | June 26, 2005, 10:49 pm |
| regex to match any url | February 14, 2006, 4:02 pm |
| regex - match anything until | September 10, 2009, 12:30 pm |
| regex match on nothing | March 4, 2010, 5:22 am |
| Printing regex match | September 25, 2004, 1:27 pm |
| regex: match at least one of two expression | October 12, 2004, 10:07 am |
| match regex split | January 5, 2005, 9:09 pm |
| RegEx How to not match a string | October 3, 2005, 3:54 pm |
|