...">

How to capture any character using regular expressions

I want to capture the text in an attribute in an XML tag. it

<tag1 name="tag^*&,+">

I want to capture the value in the name attribute (which will be in this case tag^*&,+). This is a regex

name=\"([a-z0-9]+)\"  

returns a value only if the text in the attribute is alphanumeric. Is there any syntax that will return the captured value no matter what character and characters? Thank!

+3
source share
5 answers

Check out regular-expressions.info

This will do what you want:

([^"]+)
+1
source

, "" XML . XML- . tag1 name.

, , , , escape- (, &quot;), , ...

+6

:

name=\"([^\"]+)\"

, " , "

+1

It seems that you are better off using XML Parser . I don’t know which language you are using, but there is an XML parser for each language there.

+1
source

. will match any character.

name = \"(.+)\"
0
source

Source: https://habr.com/ru/post/1735526/


All Articles