| |

VerySource

 Forgot password?
 Register
Search
View: 2090|Reply: 20

Regular expression. After searching for a long time on the Internet, there is no answer! Ask for advice online

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-16 16:30:01
| Show all posts |Read mode
For example a string:
aadfgsdg take aadfgsdg
 aajsa; kfjn take aajsa; kfjn
(adfasf) aa take aa
asfdasfaaaaas323 cannot get value
afffasfdaaakjasdfa cannot get value
adfafffdaa ........ take aa ........
Claim
1) Take the content starting from aa.
2) There may not be aa after the string, if there is, it cannot be a
3) There may not be aa before the string, if it cannot be a
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-18 06:30:01
| Show all posts
Mostly unsolved!
Reply

Use magic Report

0

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-4-19 00:30:02
| Show all posts
Do not quite understand the purpose of the landlord, but according to your requirements, use the following test, the test passes

string yourStr = textBox1.Text;
Match m = Regex.Match (yourStr, ". *? (? <! A) (aa (?! A). *)");
textBox2.Text = m.Groups [1] .Value; //Groups[1].Value is the content to be extracted
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-19 16:00:01
| Show all posts
^ (? = [^ a] *) aa [^ a] * $
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-20 08:15:01
| Show all posts
[^ a] means the inverse character set of a
aa [^ a] * means that there may be non-a characters after aa
(? = [^ a] *) means looking forward, there may be non-a characters in front but not included in the match
^ Start sign
$ End mark
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-4-21 09:15:01
| Show all posts
I wrote a troublesome ..

Regex rx = new Regex (@ "^ ([\s\S] * [^ a])? (Aa ([^ a] [\s\S] *)?) $");
Match m = rx.Match (str);
if (m.Success)
{
     Console.WriteLine (m.Groups [2] .Value);
}
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-4-21 09:45:01
| Show all posts
test:

Regex rx = new Regex (@ "^ ([\s\S] * [^ a])? (Aa ([^ a] [\s\S] *)?) $");

            string str = Console.ReadLine ();
            while (str! = "exit")
            {
                Match m = rx.Match (str);
                if (m.Success)
                {
                    Console.WriteLine (m.Groups [2] .Value);
                }
                str = Console.ReadLine ();
            }
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-26 13:30:01
| Show all posts
string str = "asfdaasfas323";
string str2 = System.Text.RegularExpressions.Regex.Replace (str, "^ aa |. *? [^ a] aa (?! a)", "$");
if (str.Equals (str2))
{
Response.Write ("Empty");
}
else
{
Response.Write (str2);
}
Haha, it's difficult, but I was blinded by me and the test passed!
Reply

Use magic Report

0

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 LAN

Post time: 2020-5-24 18:15:01
| Show all posts
string str = "adfafffdaa ........";
Regex reg = new Regex ("((? <= [^ A]) | ^) aa (([^ a]. *) | $)");
str = reg.Match (a) .Value;
// This should be fine
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-25 10:45:01
| Show all posts
^ [^ a] *? (aa (?! a). *) | [^ a] (aa [^ a] *?) $
Note: When taking values, the values ​​of $ 1 and $ 2 can be taken together. One must be empty and the other a positive solution.

aadfgsdg takes aadfgsdg (take $ 1)
 aajsa; kfjn take aajsa; kfjn (take $ 1)
(adfasf) aa take aa (take $ 2)
asfdasfaaaaas323 cannot get the value
afffasfdaaakjasdfa cannot get the value
adfafffdaa ........ Take aa ........ (take $ 2)

C # find matches:
using System.Text.RegularExpressions;

// Regular expression object
Regex re = new Regex (@ "^ [^ a] *? (Aa (?! A). *) | [^ A] (aa [^ a] *?) $");

// Match object
Match m = re.Match ("your string");

// found
if (m.Success)
{
    // turn up
}
else
{
    // Not found
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list