How to exclude content from regex? [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I would like to write a regex that finds a keyword inside some text, however it should disregard the matches that are within some given keywords.
Text example:
bla HELLO bla bla begin_not_inside_here bla bla HELLO bla bla end_not_inside_here bla bla HELLO bla bla
Expected result:
Should find first and third 'HELLO' but not the second one because it is delimited by the keywords: 'begin_not_inside_here' and 'end_not_inside_here'.
I have tried several regex but I can't find the right one, I'm not really a regex expert...

Related

Regular expression Regex to extract a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Please can somebody help me, I`m new to regex and have no idea how to do this!.
I`m trying to extract from a list which looks like this...
Joe-Age23-46737-251.aspx
Tim-Age18-46909-451.aspx
Roger-Age41-59768-251.aspx
What I want is this...
46737-251.aspx
46909-451.aspx
59768-251.aspx
so basically anything after the second to last hyphen.
Cheers
Let's translate "everything after the second-to-last hyphen" into regex:
(?<=-)[^-]*-[^-]*$
Explanation:
(?<=-) # Assert starting position right after a hyphen
[^-]* # Match zero or more characters except hyphens
- # Match a single hyphen
[^-]* # see above
$ # until end of string.
Test it live on regex101.com.
Step1 : Split the string on the basis of hyphen(-) . You will get array of strings.
Step2 : extract the second , fifth and eighth
and so on( incremented by 3 ).
Step3 : concatinate all the strings formed in step2.

Powershell pattern to exclude % [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to find a pattern to remove % from the text. This could have been easily achieved through ESCAPE or replace but I am restricted to only modify the contents of $pattern .
$text = "something is 5% and 10% value"
$pattern = "[^!%]*" // only this can be modified.
([Regex]::Match($text,$pattern)).value
Output should be :
something is 5 and 10 value
From the documentation:
Remarks
The Match(String, String) method returns the first substring that matches a regular expression pattern in an input string.
If you can only modify the pattern but not the rest of the code it's not possible to achieve what you want.
You need somthing like
$pattern = '[!%]'
[regex]::Replace($text, $pattern, '')
or
$pattern = '[!%]'
$text -replace $pattern

Regex to match custom markdown syntax [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to match the following with multiple capture groups:
Definition 1
: This is the definition text that described the term. Can have markdown formatting and
multiple lines.
Definition 2
: This is the definition text with **markdown**.`code`
I also want to replace it with the following text (HTML definition list):
<dl>
<dt>Definition 1</dt>
<dd>This is the definition text that described the term. Can have markdown formatting and
multiple lines.</dd>
<dt>Definition 1</dt>
<dd>This is the definition text with **markdown**.`code`</dd>
</dl>
You could do this in two steps:
1. Insert the dt and dd tags
Perform a search with:
(.*)\R: ((?:.+(?:\R|$))*?)(?=\R|.*\R:|$)/g
and substitute by:
<dt>$1</dt>\n<dd>$2</dd>\n
See regex tester.
2. Add the dl tags
Use the result of the previous substitution and perform the following search:
/(<dt>.*?<\/dd>(?!\s*<dt>))/gs
and substitute by:
<dl>\n$1\n</dl>
See regex tester.
Remarks
If the \R escape is not supported, use \n instead.
The back-references $1, $2 might need to be changed to \1, \2 depending on your regex engine.

Regex: Matching only groups that have a specific word embedded [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I cannot figure out how to match only on groups that contain a certain word ('test' for example below). It is a big text file and the groups start with a line 'Group x' and include text with an empty line separation to the next group. I think I need to use lookaheads and lookbehinds but don't know how. I can use vb.net for this but trying to test out different expressions in the regex testers and can't get anywhere.
Group 1
adfdf
dd test ddfdf
dfdfadf
Group 2
ddfadfa
Group 3
add test
adfdff
Group 4
adfdf
Expected 2 matches:
Group 1
adfdf
dd test ddfdf
dfdfadf
Group 3
add test
adfdff
Start your pattern with ^Group \d+$ and end with (?:^$|\Z). In the middle match test but not preceeded by an empty line $(?:.(?!^$) (see Regular expression to match a line that doesn't contain a word? for details on how the latter works). Don't forget the m and s modifiers:
^Group \d+$(?:.(?!^$))*?test.*?(?:^$|\Z)
Demo: https://regex101.com/r/kM9qB3/2

How to match a line which should not contain a word after a matched word [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
1) /abs/2-bhk-property-for-sale-in-builders-apartments-bang123asdxc/38070127?page=509
2) /vjr-apartments/private-k3zs0gdf
3) /dolphin-jasmine-apartments-navimumbai-approvals/psddp-3qfci22i
4) /kanaka-lakshmi-apartments-andra/private-67mwcdbe
What is the regex expression to match strings with 'apartment' but should not match 'private'?
i.e Should match 1) and 3) but not 2) and 4)
I wrote this regex .*?(-)(apartments)(?!\/private).* but it is not working.
You can use this regex:
-apartments(?!.*?/private)
(?!.*?/private) is negative lookahead that will fail the match if /private string comes after -apartments.
RegEx Demo
In some languages / needs to be escaped so use:
/-apartments(?!.*?\/private)/
This matches the line.
.*apartments(?!.*/private).*