I have text that starts with (parag1 level="All") as start tag and end with (/parag1) as end tag, and between them is text.
How can I with regex in C# check that the user selected text with start tag or end tags?
I use parentheses for tags: (tag)text(/tag)
Example:
(Parag1 level="All")
This is my string1. This is my string2. This is my string3.
(/Parag1)
The user may select:
(Parag1 level="All")
This is my
Or
level="All")
This is my
Or (this one is does not have the start tag)
is my string1
Or (this one has the start tag with l”) and end tag with ( )
l")
This is my string1. This is my string2. This is my string3.
(
I want to check:
-
Does it start with “start tag” or part of “start tag”?
Selected text 1 and 2,4 is ok, but 3 is no. -
Does it end with “end tag” or part of “end tag”?
Selected text 1,2,3 is no, but 4 is ok.
How can i change my regex patern that include all below text.
pattern :
(<Parag)\d+\s(Level=")\w+(">)
text :
<Parag1 Level="all">
<Parag2 Level="Total">
Parag3 Level="all">
arag4 Level="all">
rag5 Level="all">
ag6 Level="all">
g7 Level="all">
8 Level="all">
Level="all">
Level="all">
evel="all">
vel="all">
el="all">
l="all">
="all">
="all">
"all">
all">
ll">
l">
">
>
Change regex pattern c#
I know this isn’t a
RegExsolution as you requested, but here’s an outside the box idea. Since your example text has some XML-like qualities, have you considered replacing the(and)with<and>and parsing it with an XML parser?To use this solution though, your text could not have any parenthesis other than the tags, and you would have to replace any illegal characters with their respective escape sequences.
One other issue you would have to deal with is a root-level tag. If one does not exist, you would have to wrap your original string in one: