| |

VerySource

 Forgot password?
 Register
Search
Author: japanshit

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

 Author| Post time: 2020-6-12 20:30:01
| Show all posts
This is the case, I write an expression that matches all the comments in C#
//safdjkas;fjasfj messy comments
//
  
   //

  /// <sumary>
  /// I don't want to match things here
  /// </summary>
  public class TessClass//Here are the comments in scribble
  {//This is also a note
          public string f()//A lot of comments, of course, a bit messy
          {
               return "";//The ghost knows where his comments are written
          } //It's really possible
  }
  // Finished the comment
______________________________________
1) Only the comments with double slashes are matched, not the summary with three slashes! (To put it bluntly, it is to replace the comments in the program)

I tried what you wrote, and tried it in the search in EditPlus and VS2005 (a regular expression match search is provided above), but the results you wrote did not match.

My question:
Last night I thought I had a problem with the expressions I wrote. Now it seems that they may not provide the function of matching non-acquisition (that is (?|pattern)), anyway (?!pattern) and (?=pattern) You can't get anything.
-------------------------------------------------- --------------
Please give it a try, does the search in EditPlus and VS2005 not provide (?=pattern) and other matches?

Post before 9 o'clock tonight, thank you for your help!
Reply

Use magic Report

0

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 LAN

Post time: 2020-6-13 18:15:01
| Show all posts
Do you want to use a regular match for the entire file? What a big appetite
Does it match line by line?
//My matching line is no problem, I change it to see if it can match the entire file
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-14 11:45:01
| Show all posts
//([^/]*?)\r\n

(mutiline|ignore)

You take a look.
Reply

Use magic Report

0

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 LAN

Post time: 2020-6-15 09:15:01
| Show all posts
StreamReader sr=new StreamReader("..\\..\\duplicate Form1.cs");
string str=sr.ReadToEnd();
Regex reg=new Regex("((?<=[^/])|^)//(([^/].*)|$)",RegexOptions.Multiline);
string a="";
foreach(Match m in reg.Matches(str))
{
a=m.Value;
a="";
}//It should be fine just measured
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-17 01:15:02
| Show all posts
Experts:
        Help me, my brother has a question about the SPI interception network packet technology. I have intercepted the data packet and put it in the file, but I don't know how to filter the data packet. I wrote it in C++! Experts please give pointers! ! ! thank you very much! !
Reply

Use magic Report

0

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-20 21:15:01
| Show all posts
The code given upstairs can solve your problem
I thought it was what you want to extract, and the result is what you want to replace. According to your requirements, the regular I wrote can be qualified as long as the form is changed slightly, depending on which form you need

yourStr = ...........;
string resultStr = Regex.Replace(yourStr, "(.*?(?<!/))(//(?!/).*)", "$1", RegexOptions.IgnoreCase);

I haven't tried EditPlus.
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-22 23:45:01
| Show all posts
I can extract and replace
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-23 22:15:02
| Show all posts
adfafffdaa........ Take aa........

None of the above methods will work, including:

(.*?(?<!/))(//(?!/).*)

((?<=[^/])|^)//(([^/].*)|$

^[^a]*?(aa(?!a).*)|[^a](aa[^a]*?)$

(?=[^a]*)aa[^a]*$

.*?(?<!a)(aa(?!a).*)

Signed
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-6-24 23:30:02
| Show all posts
Read it line by line, and then match line by line, my one should also work...

In addition, if you want to match all the comments, why not consider the case of "/*...*/"?
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-25 13:45:01
| Show all posts
What do you use upstairs
^[^a]*?(aa(?!a).*)|[^a](aa[^a]*?)$
Although this method does not havelinhanerror((?<=[^a])|^)aa(([^a].*)|$Good
But there is no problem to test the single line, I debugged on MTracer
After get off work, don't write, I recommendlinhanerror
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