Regex for matching items from firewall syslog [closed] - regex

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to come up with a regex to extract certain pieces of information from the below log. I've been messing with regex groups for awhile and am not getting anywhere. I would like to get the date/timestamp, the usr field, dstname field, and arg field. How can I accomplish this?
May 1 08:21:02 192.168.1.1 id=firewall sn=fakeserial time="2020-05-01 12:21:02 UTC" fw=1.2.3.4 pri=3 c=4 m=14 msg="Web site access denied" app=2515 sess="Auto" n=398533 usr="sampledomain\username" src=192.168.1.150:50334:X0 dst=72.21.81.240:80:X1 srcMac=b0:00:b4:18:4a:b5 dstMac=c0:ea:e4:9d:a0:8c proto=tcp/http dstname=ctldl.windowsupdate.com arg=/msdownload/update/v3/static/trustedr/en/disallowedcertstl.cab code=99 Category="Administrative Custom List settings" fw_action="drop"

You could base it on something like this
(\w{3} \d* [\d:]*).*usr="([a-z\\]*)".*dstname=([\w.]*).*arg=([\/][^ ]*)
https://regex101.com/r/VUIBAm/1

Related

Get string between string/ and / [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Ive been trying for ages to get the id 30393 from the below string.
https://example.com/service_requests/30393/journey
Any ideas how? Its the / causing me issues. Been trying (?<=/).*?(?=/) but obviously it doesn't work.
You could try this:
\d+
DEMO: https://regex101.com/r/9JyTdx/1
OR
(?<=service_requests\/)\d+(?=\/journey)
DEMO: https://regex101.com/r/8SXJiJ/1
/^https:\/\/example.com\/service_requests\/(\d*)\/journey$/
The answer is this (?<=service_requests\/).*?(?=\/)
Some of the comments inspired me. Just made an alteration to #bhusak comment.
This might not be a job for regexes, but for existing tools in your language of choice.  Regexes are not a magic wand you wave at every problem that happens to involve strings. You probably want to use existing code that has already been written, tested, and debugged.
In PHP, use the parse_url function.
Perl: URI module.
Ruby: URI module.
.NET: 'Uri' class
Split the string on / characters and return the 2nd-to-last element. Here's the JavaScript solution, but it should be similar in other languages.
let url = 'https://example.com/service_requests/30393/journey';
let arr = url.split('/');
let id = arr[arr.length-2];
console.log(id);

How to grep a link from a html modified file that starts with http and ends with .epub? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So I have one modified html file that has some links in it, and I want to extract them (grep or similar) so I only have links that start with http://* and end with .epub, the extension).
I tried some solutions here on stackoverflow, but none seems to work as I can't seem to extract anything.
How would I go in doing this?
EDIT: The links are laid out on the file like this as well: > http://........epub" class="..."><i but I just want to extract everything between http and .epub, including those 2.
grep -o 'http://[^ "<]*.epub' file.html should do the trick

RegEx Splitting to a List<string> [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
RegEx is a bit confusing to me and I have been at it for 3.5 hours on one line.
I have a string:
" Layer 1 Layer 2 Layer 3 Layer 4 "
I would like to split it up into a List and cannot get it to work.
I tried this and it was close but still not what I am looking to do:
List<string> lineWords = Regex
.Matches(line, #"[Layier_]*\s*\s*[1-9]")
.OfType<Match>().ToArray()
.Select(match => match.Value)
.List();
Where am I in error?
Thank you.
You didn't write it explicitly, but I assume, you are using C#.
Your code requires only minor corrections:
I changed the regex a little (compare).
ToArray() is not needed.
Instead of List() use ToList().
So the code given below works.
List<string> lineWords = Regex.Matches(line, #"[Layier_]+\s*[1-9]")
.Cast<Match>()
.Select(match => match.Value)
.ToList();

Need perfact Regular Expression [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to extract information form a text using regex for statements like bellow
#1. 02/14/2013 05:21 pm - Safee Safeeul Bashir
- Status changed from New to In Progress
#2. 02/14/2013 10:43 pm - Safee Safeeul Bashir
- Status changed from In Progress to Resolved
- CL set to 1203474
#3. 08/16/2013 02:30 am - Mondal Amit Kumar
Task was automatically close beacuse last update was more than two months and the issue passed
From here I want to extract the date and time where the status is changed to resolve.
For example for this one the date with #2 **02/14/2013 10:43 pm**
How about this:
\d\d/\d\d/\d{4}\s\d\d:\d\d\s[ap]m(?=.*(\n?\r?).*Resolved)
See it on RegExr
The regex can be
\d{2}/\d{2}/\d{4}\s\d{2}:\d{2}\s[pa]m

Replace Specific Instance [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm completely new to RegEx and could really use some help with my delimma. I have a large text file of IP addresses and corresponding Hosts.
eg.
157.55.33.47 msnbot-157-55-33-47.search.msn.com
157.56.93.62 msnbot-157-56-93-62.search.msn.com
etc...
I need a find and replace algorithm that apeends to the beginning and end of each line and replaces the delimeter, which in this case is just a space.
eg. the ouput after running the regex should be
'text1' 157.55.33.47 'text2' msnbot-157-55-33-47.search.msn.com 'text3'
'text1' 157.56.93.62 'text2' msnbot-157-56-93-62.search.msn.com 'text3'
Any guidance would be greatly appreciated!
Find what:
^([\S]+)\s([\S]+)$
Replace with:
'text1' $1 'text2' $2 'text3'
You can use a Macro for this instead of a regex. Record keystrokes on the first line. I'm on a Mac right now, so I can't be sure this is right, but it should be close to:
Home, [type 'text1'], CTRL+RightArrow [repeat 7 times], [type 'text2],
space, End, space, [type 'text3'], DownArrow
Once your Macro is recorded, re-run your Macro for the entire file. Again, I can't see the exact options, but it will be something like the following:
Go to Macros>Run a Macro Multiple Times..., select Current recorded macro, and Run until the end of file.