D
D
Daniel2018-02-11 17:53:52
Java
Daniel, 2018-02-11 17:53:52

How to grab the contents of a tag that can have any characters?

You need to capture the file content line without capturing the end of the line and closing the
tags. So far decided with (.*), and then delete the last line. But this is not an option in terms of
extensibility . Instead of (.*), you need to compose a regular expression that ends after the ,
which comes before
. It must be taken into account that there may be a line in the
content of the file itself.
//

String regex="<remote\s+host="localhost"\s+port="8080">\s+<(\w+)\s+\w+="([a-zA-Z0-9]+:[a-zA-Z\\\/]*)">(.*)"
// (.*) нужно вместо нее что-то, что остановит ее.
String test="<remote host="localhost" port="8080"> <file src="C:\www\rock">file content </file></remote>"

<b>Результат на http://baco.su/articles/regulyarnye-vyrajeniya/</b>
key = 0], array (4): 
[key = 0] =>" <remote host="localhost" port="8080"> <file src="C:\www\rock">file content </file></remote>"
[key = 1] => file
[key = 2] => C:\www\rock
[key = 3] =>file content </file></remote>  /*</file></remote>  лишнее, надо остановиться. Слишком жадно*/

PS Without escaping, because toster eats everything in <> tags, so I just wrapped it in code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-02-11
@BorisKorobkov

[^<]*
PS All this is govnokod. It is more correct to use ru2.php.net/manual/ru/book.simplexml.php or a similar parser.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question