Regex Expressions for Alphanumeric and Wild characters - regex

I need to validate / search / find strings as below using regex pattern:
1/0.abc
1/0.ABC
1/2/1.xyz
1/.ddd
Can Someone help me with the regex pattern please

i think you need this :
^\d(?:\/\d)*\/?\.\w+$
this will validate your string with any type of extension
demo here : http://regex101.com/r/qE7gK5/1
in java :
^\\d(?:\\/\d)*\\/?\\.\\w+$

Depending on the language, the pattern may vary. For JavaScript, the following pattern will work:
/(\d+\/)+\d*\.[a-z]{3}/ig

Related

Regular Expression get string between char (excluded)

I need to find a regular expression to match everu char between * delimiter.
I ca have strings like these:
*1234-567*
**1234-567**
***1234-567***
*1234-567****
**1234-567****
I need to get 1234-567
I did a try with this one. The full match of this regex return also the * chars. I do ot need it.
Can you help me?
Try this pattern:
/\*+([^*]+)\*+/g
Noted that $1 contains what you need.
Online Demo
if you can utilise lookarounds (generally meaning, it isn't javascript), this will match what you want with no match groups needed:
(lookarounds being "zero-width assertions", they do not actually consume any characters)
(?<=\*)[^*\n]+(?=\*)
regex101 demo

Can't get REGEX to work ((?=(<\/))(.*?)(?:\>))

I have the following regex and it finds a partial solution for me:
((?=(<\/))(.*?)(?:\>))
Given the Following line:
</EventSubType><OrgUnitNm>###</OrgUnitNm></test:CommonAttributes><ProductArrangementBasic><ProductId>####</ProductId></part:Asking>
The regex will give me:
</EventSubType></OrgUnitNm></test:CommonAttributes></ProductId></part:Asking>
I want just:
</test: </part:
Any help would be great.
Thank you.
NOTE: if you are parsing HTML, you'd better use a dedicated library for that.
I suspect you are using the regex with PCRE /U tag, like /((?=(<\/))(.*?)(?:\>))/U.
If you want to obtain just </test: and </part:, you may use a much simpler regex:
/<\/\w+:/
See the regex demo
Details:
< - a literal <
\/ - a literal /
\w+ - 1 or more chars from [a-zA-Z0-9_] ranges
: - a literal :.

re2 does not seem to give correct results for some patterns when compared to pcre

I was trying to use both pcre and re2 and I came up with the following observation.
When I give the string as
"ab cd"
and the pattern as
"^[^c]"
re2 returns NO MATCH but its actually a match.
That is to say when I type this RE2::FullMatch("ab cd", RE2("^[^c]")) I get FAIL/No Match.
Please let me know if I am going wrong somewhere or what is the problem?
RE2::FullMatch matches the entire string, like Jerry says.
There are two basic operators: RE2::FullMatch requires the regexp to
match the entire input text, and RE2::PartialMatch looks for a match
for a substring of the input text, returning the leftmost-longest
match in POSIX mode and the same match that Perl would have chosen in
Perl mode.
https://code.google.com/p/re2/wiki/CplusplusAPI

Regular expression to match particular starting word or nothing

I'm struggling to come up with the correct regex for the following scenario.
Let's say you have to match a word either starts with http- or nothing
eg : http-test-data, test-data should be a match but xyz-test-data shouldn't be a match
the regex i came up so far is
(?:http-)?(test-data)
but it matches xyz-test-data as well.
You could simply use the following:
(?:http-|^)(test-data)
This tests for either a positive look-behind of http- or for the beginning of the string before test-data.
For example, for the sample data as follows:
http-test-data
xyz-test-data
http-test-data
xyz-test-data
test-data
yes-yes-test-data
-test-data
It yeilds:
http-test-data
http-test-data
test-data
Try this representation
^(http-|)(test-data)
Yes because there is a ? on the (?:http-). Then the regex will also match any string that contains test-data.

Regular Expression Pattern To Accept An Apostrophe

I am using Regular Expression in Jquery to validate names.I am having this issue that i need a pattern which will allow an apostrophe in the name.That means it can have alphabets and a single apostrophe.
Valid: D'souza,Danny
Invalid: D''souza
Can anybody help me out with this.Currently I am using this pattern
var rxPattern = /^([a-zA-Z]+)$/;
Thanks
You probably need something like that:
[a-zA-Z]+('[a-zA-Z])?[a-zA-Z]*