Probably, this regular expression seems to be nailed, what is connected with it?

I am trying to cut pairs of values ​​from a string. For example, using:

key=cat key2=dog 

I use the expression:

([^=])([\w-\s]*)\s

What gives me:

cat dog

However, in reality, the search string is likely to contain other non-alphabet characters, such as:

192.168.20.31 Url=/flash/56553550_hi.mp4 Log=SESSIONSTART 
[16/Dec/2010:13:44:17 +0000] flash/56553550_hi.mp4 0 192.168.20.31 1 
[16/Dec/2010:13:44:17 +0000] 0 0 0 [0 No Error] 
[0 No Error [rtmp://helix.pete.videolibraryserver.com/flash/56553550_hi.mp4] 

And I need to remove the URL from it. However, I'm not sure how I introduce a trick for all character types into my original regular expression. can someone show me?

+3
source share
3 answers

Try it. Works like beauty for me:

((?<=key[0-9]?=)[^\s]*(\s|$))+

(?<=regex) - ( ) . , key[0-9]?=. [0-9] , ? . , : [^\s]. , * , (\s|$).


Update

blob , , , , :

([^\s]+)=(.+?(?=([^\s]+=|$)))

, ( / , ).

:

Url, /flash/56553550_hi.mp4

Log, SESSIONSTART [16/Dec/2010:13:44:17 +0000] flash/56553550_hi.mp4 0 192.168.20.31 1 [16/Dec/2010:13:44:17 +0000] 0 0 0 [0 No Error] [0 No Error [rtmp://helix.pete.videolibraryserver.com/flash/56553550_hi.mp4]

( ):

[^\s]+=(.+?(?=([^\s]+=|$)))

RegEx

RegEx

+3

, , Url=:

\bUrl=(\S*)

, , - /, :

\b(\S*)=(\S*)
+1

Assuming the value of your Url only allows: alphanumeric, '.' and '_'; this regular expression should retrieve the value of the url.

URL = ((\ w | /? |.) *)

Code to retrieve the value:


Regex regex = new Regex(@"Url=(?(\w|/|\.)*)");
MatchCollection matchCollection = regex.Matches(inputString);

foreach(Match match in matchCollection)
{
    Console.WriteLine(match.Groups["url"].Value);
}
+1
source

Source: https://habr.com/ru/post/1780691/


All Articles