| |

VerySource

 Forgot password?
 Register
Search
View: 1243|Reply: 11

Urgent: Find a replacement regular, such as: [by: 郑信涛], [01: 18.50], [ar: 同 恩] That is, replace [content]

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-23 17:00:02
| Show all posts |Read mode
Such as the title:
Find a replacement regular, such as: [by: 郑信涛], [01: 18.50], [ar: 同 恩]
That is: replace [content] with empty
Asp.net C # to replace. Waiting online
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-7 10:30:01
| Show all posts
Regex regex = new Regex ("[. *]");
string outputStr = regex.Replace (inputStr, string.Empty);
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-7 11:30:02
| Show all posts
wenmy715
 
 
   Regex regex = new Regex ("[. *]");
string outputStr = regex.Replace (inputStr, string.Empty);
  
 
------------------------------------------------------------------------------------------------------------------------------------------------------------
It's not that simple. . . . . . . . . .
I was thinking about this last time myself
But the problem when matching is
For example: [by: 郑信涛], [01: 18.50], [ar: 同 恩]
He matched into [by: 郑信涛], [01: 18.50], [ar: 同 恩]
Instead of [by: 郑信涛]
[01: 18.50]
[ar: Tongen]
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-7 11:45:01
| Show all posts
wenmy715
 
 
   Regex regex = new Regex ("[. *]");
string outputStr = regex.Replace (inputStr, string.Empty);
  
 
------------------------------------------------------------------------------------------------------
And for regular square bracket matching, use escape\[
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-7 13:30:01
| Show all posts
using System.Text.RegularExpressions;

// regular expression object
Regex re = new Regex (@ "\[[A-Za-z0-9 _] *\]");

// replace
string oldstr = "your string";

string newstr = re.Replace (oldstr, "replace to");

This is the character match I wrote
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-7 14:00:01
| Show all posts
Eh, sorry, I found this problem too, I think about it ~~
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-7 14:30:01
| Show all posts
But I do n’t seem to know about Chinese character matching.
Han, I did n’t find out for a long time
The regular expression I just wrote is
\[[A-Za-z0-9 _] *\]
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-7 14:45:02
| Show all posts
Yes. None of the above methods work, is there no other way
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-7 18:15:01
| Show all posts
Try this ~~
Regex regex = new Regex (@ "\[. *\] |\[. *]\],");
string outputStr = regex.Replace (inputStr, "");
Reply

Use magic Report

0

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-2-9 06:45:01
| Show all posts
I don't quite understand the meaning of the landlord, but to replace each [content] of "[by: 郑信涛], [01: 18.50], [ar: 同 恩]", and keep the symbols in it, or the above Replace all the contents, if it is the former, use the following

string yourStr = ......;
string resultStr = Regex.Replace (yourStr, "\\[. *?\\]", "", RegexOptions.IgnoreCase);

If the latter, use the following

string yourStr = ......;
string resultStr = Regex.Replace (yourStr, "\\[. *\\]", "", RegexOptions.IgnoreCase);
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