Я пытаюсь использовать. net регулярное выражение для идентификации строк в XML данных, которые не содержат точку остановки перед последним тегом. У меня не так много опыта с регулярными выражениями. Я не уверен, что мне нужно изменить и зачем получить результат, который я ищу.
В конце каждой строки в данных есть разрывы строк и возврат каретки.
Схема используется для XML.
Пример хорошего XML Данные:
<randlist prefix="unorder">
<item>abc</item>
<item>abc</item>
<item>abc.</item>
</randlist>
Пример плохого XML Данные - регулярное выражение должно дать совпадения - нет полной остановки перед последним </item>
:
<randlist prefix="unorder">
<item>abc</item>
<item>abc</item>
<item>abc</item>
</randlist>
Шаблон регулярного выражения Я пробовал, что не работало с плохими данными XML (не проверено на хороших данных XML):
^<randlist \w*=[\S\s]*\.*[^.]<\/item>[\n]*<\/randlist>$
Результаты с использованием http://regexstorm.net/tester:
0 matches
Результаты с использованием https://regex101.com/:
0 matches
This вопрос отличается от следующего imo, из-за полного останова и начала строковых критериев:
регулярное выражение для строки, не заканчивающейся данным суффиксом
Пояснение от 3 :
/
^<randlist \w*=[\S\s]*\.*[^.]<\/item>[\n]*<\/randlist>$
/
gm
^ asserts position at start of a line
<randlist matches the characters <randlist literally (case sensitive)
\w* matches any word character (equal to [a-zA-Z0-9_])
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
= matches the character = literally (case sensitive)
Match a single character present in the list below [\S\s]*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\S matches any non-whitespace character (equal to [^\r\n\t\f\v ])
\s matches any whitespace character (equal to [\r\n\t\f\v ])
\.* matches the character . literally (case sensitive)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character not present in the list below [^.]
. matches the character . literally (case sensitive)
< matches the character < literally (case sensitive)
\/ matches the character / literally (case sensitive)
item> matches the characters item> literally (case sensitive)
Match a single character present in the list below [\n]*
< matches the character < literally (case sensitive)
\/ matches the character / literally (case sensitive)
randlist> matches the characters randlist> literally (case sensitive)
$ asserts position at the end of a line
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)