How to correct regular expression - regex

I have something like this https://regexr.com/3ja39 and the question is: How should I change regexp to get value beetween lot and ohm but without lot and ohm I want to get only value which is beetewm

Use parenthesis in Regex to capture specific text between other characters, if this is always going to be a numeric between lot- and -ohm you could do something like:
.?lot-(\d.)-ohm.*?
I like this site, it has a great cheat sheet on the regex characters and what they do Regex Cheatsheet!
Javascript Regex

Related

REGEX, searching for emails with a certain defined length, prefix & domain? (attempted but failed)

Hi i'm doing some infosec research and searching through text bins.
I'm using a text editor to search files and I'm wanting to search for email addresses with certain conditions. Text is comma-separated.
Say for example i know the email is 20 chars long and I know that the domain is gmail.com, and I also know it starts with t.
[tT](.{9})#gmail.com
If it was correct it should pick up for example: tqwertyuio#gmail.com and tzxcvb1234#gmail.com. Right?
I'm using emEditor which uses Boost Regex engine I think. This regex is just not working as it also returns anything that has that expression in it.
I've tried to use anchors, but they are not working. Perhaps its this engine. I would of thought i would go:
^[tT](.{9})#gmail.com$
But it's not working. Any help?? Thanks SO much i really just want to learn why i cant do this.
I believe you are looking for 20 characters long email which are NOT surrounded by alphabets or numbers. In that case, you can search for:
(?<!\w)[tT](.{9})#gmail.com(?!\w)
where \w is an alphabet or a number, (?<!\w) is negative lookbehind, and (?!\w) is negative lookahead.
In the Find dialog box, you can enter this regular expression, and make sure you select the "Regular Expressions" option.
You might also want to try the Filter toolbar with the same regular expression.

Extract only the text field needed

I am at the beginning of learning Regex, and I use every opportunity to understand how it's working. Currently I am trying to extract dates from a text file (which is in fact a vnt-file type from my mobile phone). It looks like following:
BEGIN:VNOTE
VERSION:1.1
BODY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:18.07.=0A14.08.=0A15.09.=0A15.10.=
=0A13.11.=0A13.12.=0A12.01.=0A03.02. Grippe=0A06.03.=0A04.04.2015=0A0=
5.05.2015=0A03.06.2015=0A03.07.2015=0A02.08.2015=0A30.08.2015=0A28.09=
17.11.2017=0A
DCREATED:20171118T095601
X-IRMC-LUID:150
END:VNOTE
I want to extract all dates, so that the final list is like that:
18.07.
14.08.
15.09.
15.10.
and so on. If the date has also a year, it should also be displayed.
I almost found out how to detect the dates by the following regex:
.+(\d\d\.\d\d\.(2015|2016|2017)?).+
But it only detect very few of the dates. The result is this:
BEGIN:VNOTE
VERSION:1.1
15.10.
04.04.2015
30.08.2015
24.01.2016
DCREATED:20171118T075601
X-IRMC-LUID:150
END:VNOTE
Then I tried to add a question mark which makes the .+ not greedy, as far as I read in tutorials. Then the regex looks like:
.+?(\d\d\.\d\d\.(2015|2016|2017)?).+?
But the result is still not what I am looking for:
BEGIN:VNOTE
VERSION:1.1
21.03.20.04.18.05.18.06.18.07.14.08.15.09.15.10.
13.11.13.12.12.01.03.02.06.03.04.04.20150A0=
03.06.201503.07.201502.08.201530.08.20150A28.09=
28.10.201525.11.201528.12.201524.01.20160A
DCREATED:20171118T075601
X-IRMC-LUID:150
END:VNOTE
For someone who is familiar with regex I am pretty sure this is very easy to solve, but I don't get it. It's very confusing when you are new to regex. I tried to find a hint in some tutorials or stackoverflow posts, but all I found is this: Notepad++ how to extract only the text field which is needed?
But it doesn't work for me. I assume it might have something to do with the fact that my text file is not one single line.
I have my example on regex101 too.
I would be very thankful if maybe someone can give me a hint what else I can try.
Edit: I would like to detect the dates with the regex and as a result have a list with only the dates (maybe it is called substitute?)
Edit 2: Sorry for not mentioning it earlier: I just want to use the regex in e.g. Notepad++ or an online regex test website. Just to get the result of the dates and save the result in a new txt-file. I don't want to use the regex in an programming language. My apologies for not being precisely before.
Edit 3: The result should be a list with the dates, and each date in a new line:
I want to extract all dates, so that the final list is like that:
18.07.
14.08.
15.09.
15.10.
I suggest this pattern:
(?:.*?|\G)(\d\d\.\d\d\.(?:\d{4})?)
This makes use of the \G flag that, in this case, allows for multiple matches from the very start of the match without letting any single unmatched character in the text, thus allowing the removal of all but what's wanted.
If you want to remove the extra matches as well, add |.* at the end:
(?:.*?|\G)(\d\d\.\d\d\.(?:\d{4})?)|.*
regex101 demo
In N++, make sure the options underlined are selected, and that the cursor is at the beginning. In the picture below, I replaced then undid the replacement, only to show that matches were identified (16 replacements).
You can try using the following pattern:
\d{2}\.\d{2}\.(?:\d{4})?
This will match day.month dates of the form 18.07., but it also allows such a date to be followed by a four digit year, e.g. 18.07.2017. While it would be nice to make the pattern more restrictive, to avoid false fire matches, I do not see anything obvious which can be added to the above pattern. Follow the demo link below to see the pattern in action.
Demo

Regex in Golang: How to set character that makes the string not match?

I am a noob about regular expressions (sorry).
I was trying to make a very simple markup language that matches bold and italic and then converts them to HTML.
Here is an example for bold that I'm using:
var bold = regexp.MustCompile("\\*([^\\*]+)\\*")
It matches everything between two asterisks. Now, I'd like it to match *test* but not \*test*. Since I don't know much about regular expressions but I'm trying to make this experiment, I'd like to know what's the way for that. I searched everywhere but couldn't find the way to make this work.
Updated
Go does not support lookbehinds. So a workaround can be:
(?:\A|(?:[^\\]+|\A)(\\{2})+|[^\\])\*([^\\*]+)\*

Matching a substring using a regular expression in PowerShell

Regular expressions are really not my forte and I am trying to learn. Struggling with this one at the moment.
<fraglink id="230681395" resid="1057000484">
I have a file with loads of text in it, and every now and then bits like the above appear in it. I want to get the number in between the quotes after resid=.
Is some sort of look ahead / behind required here?
It looks like you want a regex like:
resid="([0-9]+)"
And to grab $1.
Since your content looks like XML, you should probably not use a regular expression to grab your desired value. If you share your whole file we will show you how to select the value properly using XPath for example.
However, if you want to use a regular expression for training purposes, try this:
$content = Get-Content 'your_file_path' -raw
[regex]::Match($content, '\bresid="([^"]+)').Groups[1].Value
Using a lookahead ((?<=pattern)), your pattern could look like:
(?<=resid=")\d+
With Regex.Match():
$id = [regex]::Match($inputString,'(?<=resid=")\d+').Value

Regex and Yahoo Pipes: How to replace end of url

Here's the Pipe though you may not need it to answer the question: http://pipes.yahoo.com/pipes/pipe.info?_id=85a288a1517e615b765df9603fd604bd
I am trying to modify all url's as so:
http://mediadownloads.mlb.com/mlbam/2009/08/12/mlbf_6073553_th_3.jpg with
http://mediadownloads.mlb.com/mlbam/2009/08/12/mlbtv_6073553_1m.mp4
The syntax should be something like:
In item.mediaUrl replace f with tv and In item.mediaUrl replace last 8 characters with 1m.mp4
mlbf_(\d+)_.* replaced w/ mlbtv_$1_1m.mp4
breaks the rss feed though I know I am close
Any idea as to what syntax I need there?
Your regex and replacement look okay to me, assuming the regex is being applied only to the URLs. If it were being applied to the surrounding text as well, the .* would tend to consume a lot more than you wanted. See what happens if you change the regex to this:
mlbf_(\d+)_[\w.]+
I do not know how this yahoo pipes work, but this regex should do it according this site:
Regex:
.*?/([0-9]*)/([0-9]*)/([0-9]*)/mlbf_([0-9]*)_.*
Substitution:
http://mediadownloads.mlb.com/mlbam/$1/$2/$3/mlbtv_$4_1m.mp4