Replace Specific Instance [closed] - regex

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.

Related

Regex for matching items from firewall syslog [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 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

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: finding a number between a range with decimals [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 8 years ago.
Improve this question
I can not for the life of me get my head around this regex stuff after a few days of fiddling around I find myself seeking help from those wiser than I. Could any of you kind souls write me a line(s) that will find and match a number between 0.00 and x.xx? I do need the decimals however so hopefully this can be done.
I actually tried using
(\b|^)(0.00|0.01|0.02)(\b|$)
until x.xx and so forth but I couldn't fit the rest of it in because I need it to go into the 100.00+. Would anyone mind whipping something up real quick for me? : ) I would appreciate it more than you can imagine! Thanks very much for your time.
Ray.
Edit:
So i forgot to explain what I'm trying to achieve here, I'm using it in conjunction with a Chrome addon called Page Monitor (life saver folks try it out when you have time to kill!) which pings every time an a website updates, this also works for shares but I'm trying to make it only alert me when the price drops below a certain point eg $4.99 per share, will (\b|^)([0-9]+\.[0-9]{2})(\b|$) and ([0-9]+.[0-9]+) suffice?
Why isn't this good enough: ([0-9]+\.[0-9]+) ?
If you can give an example of input and what is the output you expect, it would be easier to write a regex.
Updated: $ sign is a reserved character in RegEx, it means end-of-line, so you need to use \$, if you plan on using it.
So your regex would be \$([0-9]+\.[0-9]+), this would capture your $4.99 and $5.10, etc, not just $4.99
Regexs in general are good at capturing data, less at analyzing it, but if you must, you can do this to determine when the price goes below $4.99 =>
\$(([0-3]\.[0-9]+)|(4\.[0-8][0-9])|(4\.9[0-8]))
It should be obvious that its a waste of resource :)
Didn't provide enough info but this will match if the number is the entire value or if it is within a larger string and the number is not withing something else like "foo8.9bar". This will match any 1 or more digit number on the left side of the decimal and exactly 2 numbers on the right side
(\b|^)([0-9]+\.[0-9]{2})(\b|$)
(\b|^) and (\b|$) are redundant because \b implies ^ and $.
this regex: (\d+\.\d{2}) should do it.

RegEx ActionScript 3 [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 am trying to figure out a regex to strip extra single quotes so that I would end up with only one single quote. To explain my question better, here is an example.
Let's say I have 3 different strings such as this ones.
(two single quotes)
Name<span fontSize=''16'' baselineShift=''superscript''>ABC</span>
(three single quotes)
Name<span fontSize='''16''' baselineShift='''superscript'''>ABC</span>
(four single quotes)
Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>
I am trying to sanitize the string to end up with this:
Name<span fontSize='16' baselineShift='superscript'>ABC</span>
I tried several online tools. This one is my favourite one: http://ryanswanson.com/regexp/#start. But I just can't get it right.
Could someone please help me out? Any tips and suggestions would be greatly appreciated.
Thank you in advance!
Did you try '+?
var str:String = "Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>";
trace( str.replace(/'+/g, "'") );
Have you looked at the docs for AS3's RegEx code? AS3 Replace
You could try something like this
var myPattern:RegExp = /'{2,100}/g;
var str:String = "fontSize=''''16''''";
trace(str.replace(myPattern, "'"));
The '{2,100} essentially looks for a match of ' that occurs between 2 - 100 times and replaces it with a single '.

RegExp Remove content outside of commas [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 8 years ago.
Improve this question
Alright, so I have a database where you can get information from that'll show off in this kind of way:
ID, Display name, Likes Cake, Likes Coffee, Likes Dogs
So if you get the information, it would show something a little like to this:
1,anonymous,1,0,1
Now it's not very popular so I would like to show the people who has answered this so I would like the "1,!anonymous!,1,0,1" (anything outside the !'s) gone. I looked around and found a RegExp code that would remove stuff outside quotes, but it's rather hard and I'm rather impatient to put all the display names in quotes.
So if there was a RegExp that would erase the numbers so I could put the usernames up, would be delicious.
Well, you could do something like this:
Replae '^[^,]+([^,]+).*' With '$1'
How it looks exactly in your language may vary, of course.
But in your case this looks like CSV, so isn't parsing the CSV file easier in that case? E.g. in PowerShell you could do
Import-Csv foo.csv | select 'Display name'
and likewise for other languages that have such parsing built-in somewhere. Besides, most other options may break depending on the input because fields in CSV may contain commas too which breaks both above regex and a naïve splitting method.
You can split the database result string and then get the relevant array index.
string dbString = "1,anonymous,1,0,1";
string username = dbString.Split(',')[1];
//value of username will be "anonymous"