Regex: Find a string without a particular character in a particular spot - regex

I am trying to find a single-line string using the following regex:
=949.+\$h[^1]\$.+
However, the \$h[^1]\$ string can contain 10 and 11 in addition to a 1. I want to find the tens and elevens but NOT the ones.
So I want to find:
$h10 and $h11 but NOT $h1
Thoughts?
to clarify, I'd like it to find 2,3,4,5,6,7,8,9,10,11 but not 1

You can use this:
\$h(2|3|4|5|6|7|8|9|10|11)
DEMO:
http://regex101.com/r/lX4mS5
If you want to match everything except $h1, you can use a negative look-behind, like this:
\$h[\d]{1,2}(?<!(\$h1))
DEMO:
http://regex101.com/r/bS8mA2

Another option (without looking around):
\$h([2-9]|\d{2,})
Debuggex Demo

Related

Regex match last occurrence between 2 strings

I have a string like this:
abcabcdeabc...STRING INSIDE...xyz
I want to find "...STRING INSIDE..." so I'm using the regex below to match it:
(?<=abc).*(?=xyz)
The issue is there are duplicated "abc" in the string so it returns "abcdeabc...STRING INSIDE..." but I only want to match anything between the last "abc" and "xyz". Is this possible? And if yes, how can I achieve this? Thank you.
Try it here:
https://regex101.com/r/gS9Xso/3
Try this pattern:
.*(?<=abc)(.*)(?=xyz)
The leading .* will consume everything up until the last abc, then the number will be captured.
Demo
We can also try using the following pattern:
.*abc(.*?)xyz
Here is a demo for the second pattern:
Demo
This should work well.
[^\d]*abc(\d+)xyz[^\d]*
See it on Debuggex

Regexp: replacing all [[??]] with {{param|??}}

I'm hoping some regexp guru to help me out with this:
I have strings such as [[AB]], [[ABC]] and [[BEC]], and I want to replace them with string {{param|AB}}, {{param|ABC}} and {{param|BEC}} respectively.
All source strings are inside [[]] and have 2 or 3 upper case letters. The idea is to transfer the letters inside brackets to the new format. It's fine if I need two different regexps for 2 and 3 letter long cases.
(if curious, this is for replacing large number of links with templates in a Mediawiki based page).
Thanks in advance!
You can replace the result of following regex :
/\[\[([A-Z]{2,3})\]\]/
with :
{{/param\|\1/}}
Not that some regex engines use $ for capture group so you may need to use {{/param\|$1/}}
If you want to exclude some words you can use a negative look ahead :
/^\[\[((?!AAA|BBB|CCC)[A-Z]{2,3})]]$/gm
But note that since that preceding regex use anchors if you are dealing with a multiline string you need to use m flag (multiline flag).
See demo https://regex101.com/r/cR8zG6/1
You can search using this regex:
\[\[(\w+)\]\]
and replace using:
{{param|$1}}
RegEx Demo

Reg ex matching a word

I need to match only first two files, out of four files listed below:
ABD_DEF_GHIJ_20150611
ABD_DEF_GHIJ
ABD_DEF_GHIJ_FX_20150611
ABD_DEF_GHIJ_FX
I am using reg ex - ABD_DEF_GHIJ(_\d{8}|\b) and it's working fine. I would like to know if my solution is ok or there is any better alternate solution.
You could use a negative lookahead which will exclude those having _FX following the initial alpha string
^ABD_DEF_GHIJ(?!_FX)(?:_\d{8})?$
see example here
Use anchors and make the number part as optional.
^ABD_DEF_GHIJ(?:_\d{8})?$
DEMO
seems like you don't want to include files with FX, use negative look ahead, you can also append the optional (_\d{8})? if you think it's necessary
^ABD_DEF_GHIJ(?!_FX)
DEMO
DEMO 2
Try this RegEx:
ABD_DEF_GHIJ(?!_FX_?)(_\d{8})?
On regexpal.com:
This also works:
\bABD_DEF_GHIJ(?!_FX_?)(_\d{8}|\b)

How to select text between greater than and less than with an additional slash

I'm trying to select text between ></ . Example below I want "text"
>text</
but I'm unable to do so.
tried the following but it doesn't like the slash at the end of the regex
\>(.*?)\<\
I'm trying to do this in TextPad. How is this supposed to be done?
I'm ultimately wanting to delete all text between these two characters so all I'm left with is something like: <element></element>
RegEx wise, you can use 3 groupings and for the replace only use the first and 3rd group: \1\3.
Find: (>)(.*)(</)
Replace: \1\3
Try doing:
\>(.*?)\<\/
The regex that you were trying would actually have given error because you had a \ and nothing after that.
You are close.. use the following:
(>).*?(<\/)
And replace with \1\2
See DEMO
OR
You can use lookbehind and lookaheads:
(?<=>)(.*?)(?=<\/)
And replace with '' (empty string)
See DEMO

Find first point with regex

I want a regex which return me only characters before first point.
Ex :
T420_02.DOMAIN.LOCAL
I want only T420_02
Please help me.
You can use the following regex: ^(.*?)(?=\.)
The captured group contains what you need (T420_02 in your example).
This simple expression should do what you need, assuming you want to match it at the beginning of the string:
^(.+?)\.
The capture group contains the string before (but not including) the ..
Here's a fiddle: http://www.rexfiddle.net/s8l0bn3
Use regex pattern ^[^.]+(?=[.])