I'd like to find a decimal number in url with notepad++ - regex

I'd like to find a string in url with notepad++ regular expression. Unfortunately I can't.
http://www.example.com/profile/mera-handelsgesellschaft-mbh-182055?category_id=154331
What I want to have is 182055
I will only find it. Not change.
My last try was ([^\-|^\=])(\d+)([^\?])
How can I find it

try this regex please:
\d+(?=\?)
\d look for a digits
\d+ look for one or more digits
(?=\?) is a Positive Lookahead. This means that select one or more digits that there is a ? character after them.
from regex101:
\d+ match a digit [0-9]
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
(?=\?) Positive Lookahead - Assert that the regex below can be matched
\? matches the character ? literally
Regex101 Demo

Related

Regex TRYING to search with multiple criteria or backwards

Appreciating regex but still beginning.
I tried many workarounds but can't figure how to solve my problem.
String A : 4 x 120glgt
String B : 120glgt
I'd like the proper regex to return 120 as the number after "x".
But sometimes there won't be "x". So, be it [A] or [B] looking for one unique approach.
I tried :
to start the search from the END
Start right after the "x"
I clearly have some syntax issues and didn't quite get the logic of (?=)
(?=[^x])(?=[0-9]+)
So looking forward to learn with your help
As you tagged pcre, you could optionally match the leading digits followed by x and use \K to clear the match buffer to only match the digits after it.
^(?:\d+\h*x\h*)?\K\d+
The pattern matches:
^ Start of string
(?:\d+\h*x\h*)? Optionally match 1+ digits followed by x between optional spaces
\K Forget what is matched so far
\d+ Match 1+ digits
See a regex demo.
If you want to use a lookahead variant, you might use
\d+(?=[^\r\n\dx]*$)
This pattern matches:
\d+ Match 1+ digits
(?= Positive lookahead, assert what is to the right is
[^\r\n\dx]*$ Match optional repetitions of any char except a digit, x or a newline
) Close the lookahead
See another regex demo.

In Scala, is it possible to insert commas via a regex to separate thousands in numbers?

In Scala, is it possible to actually insert commas via a regex to separate thousands in numbers where the comma definitely is not there to start with?
For example, I'd like to convert 30000.00 into 30,000.00.
I am not sure this is exactly what you need, but you can use this:
val formatter = java.text.NumberFormat.getNumberInstance
println(formatter.format(30000.00)) // prints 30,000
This is not scala based answer.
You can use regex \d{1,3}(?=(?:\d{3})+\.) to find the matches and substitute each match with the same match plus an extra comma $0,.
See the online demo.
Explanation:
\d{1,3} This matches a decimal character between 1 and 3 times
(?= Positive lookahead starts
(?: This indicates a Non-capturing group
\d{3} matches a digit exactly 3 times
) end of Non-capturing group.
+ matches the previous group one or more times
\. matches the character . literally
) Positive lookahead ends.

How to consume lookaround in regex?

I want to match
abc_def_ghi,
abc_abc_ghi,
abc_a2a_ghi,
abc_999_ghi
but not abc_xxx_ghi (with xxx in center).
I came up to manually consuming look ahead (abc_(?!xxx)..._ghi), but I wonder is there any other way without manually specifying number of characters to skip.
Original qustion was with numbers, updated for strings case.
If you don't want to specify exactly how many characters to skip, perhaps you could use a quantifier like + in the negative lookahead and use a negated character class to match not an underscore.
\babc_(?!x+_)[^_]+_ghi\b
Explanation
\babc_ Word boundary, match abc_
(?! Negative lookahead, assert what is directly on the right is not
x+_ Match 1+ times x followed by an underscore
) Close lookahead
[^_]+_ Negated character class, match 1+ times any char except _
ghi\b Match ghi and word boundary
Regex demo
You can use this
123_(?:(?!000)\d){3}_789
Regex demo
If you don't wish to use look-arounds, this expression might be an option:
(?:abc_xxx_ghi)|(abc_.{3}_ghi)
Other than that I can't think of anything else.
DEMO

Regex to match this pattern (numbers must be between brackets divided by minus)

I want to match a pattern with regex, the pattern is:
A-Za-z1-9[0-9-0-9]
so for example:
test1[1-50]
Can you help me ?
Solution update:
^[A-Za-z0-9]+\[[0-9]+-[0-9]+]$
Use this regex: [A-Za-z]+[1-9]\[[0-9]+-[0-9]+\]. You might also want to add \b at the start of the regex to match only after non words character.
[A-Za-z]+ matches things like test, only letters are accepted, one or more times
[1-9] matches a any digit but 0
\[[0-9]+-[0-9]+\] matches one or more digits twice and separated with -. All this must be enclosed with square brackets. (You need to escape those with \ because they are metacharacters)

Regex: how to use lookahead/lookbehind on the result of a pattern?

I'm trying to learn more about regex today.
I'm simply trying to match an order number not surrounded by brackets (#1234 but not [#1234]) but my question is more in general about using lookahead assertions on an arbitrary pattern.
On my first attempts I noticed my negative lookahead match \d+(?!\]) would cause the \d+ to keep matching digits until it wasn't followed by a ]. I need the digits to match only if their entirety isn't followed by a ].
My current solution kills the match at the first digit by looking ahead to see if there's a ] in the digit chain.
Is this a standard way to go about this? I'm just repeating the match pattern in the lookahead. If this were a more complex regex, would I approach it the same? Repeat the valid match followed by the invalid match and have the regex engine repeat itself for every letter?
For valid matches, it would have to match itself as many times as the characters in the match.
(?<!\[) # not preceded by [
#\d+
(?!\d*\]) # not followed zero+ digits and ]
# or (?!\d|\]) # not followed by digit or ]
I'd appreciate any feedback!
You can achieve what you want by using a possessive quantifier along with lookarounds like this
(?<!\[)#\d++(?!\])
The problem in your case is when you use \d+ it allows backtracking and ends up having a partial match #123. Once you change that to possessive quantifier, it will not backtrack and only match if the sequence of digits is not preceded/followed by brackets.
Live Demo
Edit
If possessive quantifiers are not supported then you can use this one
#\d(?<!\[#\d)(?!\d*\])\d*