I'm writing a wildcard string in Word that should match:
{0>yadayada<}100{>yadayada<0}
Where yadayada can be anything EXCEPT the start of a new delimiter denoted by: {0>
This is what I have so far:
(\{0\>)*(\<\}100\{\>)*(\<0\})
This works except that the first '*' keeps matching tekst until it finds <}100{>yadayada<0}
I need to change it so that the * selects everything EXCEPT strings that contain '{0>'
I tried this by changing the first * with
[!(\{0>)]*
Or everything together:
(\{0\>)[!(\{0>)]*(\<\}100\{\>)*(\<0\})
But this evidently doesn't work.
Please help!
Try this:
\{0>.+?(?=\{0>)
You only need to escape the \{
What this regular expression says is:
Match all strings containging {0> then any text one or more times .+ and the ? at the end tells the regex engine to do a lazy search, since .+ will consume all characters if you let it. The lazy search says find the least amount of characters until the next part of the regex can take over.
Then the (?=\{0>) says to match the next deliminter but do not include it in selection.
Hope this helps!
Related
1) First I want to search a text with pattern such as
app(abs(something),abs(something))
in a large text using Notepad++, a sample of the text shown below:
app(abs(any length of characters here),abs(any length of characters here)),
tapp(abs(any length of characters here),abs(any length of characters here)),
app(abs(any length of characters here),app(any length of characters here)),
app(abs(any length of characters here),some(any length of characters here)),
app(abs(any length of characters here)) ,abs(any length of characters here))
when I use "app(abs((.?)),abs((.?)))" to search it finds first and second line in above sample.
The second line is not what I am searching.
what is wrong with my expression?
2) If possible ,I want the opened and closed parenthesis ( ) after each "abs" should matched, such as
"app( abs(..(..)..),abs(..(..(...)..)..) )"
but not as
"app(abs((), abs())"
where first abs has unmatched parenthesis.
Please give some advice!
Thanks in advance
Yes, you should switch Search Mode to Regular expression (at the bottom of Find dialog) and use regular expression as a pattern.
Assuming that asterisk in your pattern means any single character, you should replace * with . (matches any single character in the regular expression syntax) and put \ before each parenthesis (( and ) are special characters and have to be escaped using \). Thus, you will get:
str1\(str2\(.....\),str2\(........\)\)
To make it less ugly, you can replace 5 dots with .{5}
str1\(str2\(.{5}\),str2\(.{8}\)\)
Answer to the first part updated question
Actualy, pattern above doesn't give the results that you describe. .? matches zero or one any character and parentheses are interpreted as special symbols. Thus, your pattern matches strings like appabsX,abs.
It should be modified like this:
app\(abs\((.*)\),abs\((.*)\)\)
it finds first and second line in above sample
Actually, it finds a part of the second line between t and , and it's correct behavior. If you want to ignore such cases, you should somehow specify the beginning of string you are searching. Some examples:
^ matches the begging of line:
^app\(abs\((.*)\),abs\((.*)\)\)
(\s+) matches at least one white space character
(\s+)app\(abs\((.*)\),abs\((.*)\)\)
Also, it would be better to enable lazy matching by putting ? after *, like this:
^app\(abs\((.*?)\),abs\((.*?)\)\)
Is that possible in Notepad++?
Yes it is possible with regular expressions.
How to do it?
Take a look at that link: Regular Expressions Notepad
Look at that link if you want to learn more about learning, Building and testing regular expressions:
RegExr
Something like this:
^app\(abs\((.*?)\),abs\((.*?)\)\)
checkbox in search window ". matches new line" need unchecked.
I'm using Regex to match whole sentences in a text containing a certain string. This is working fine as long as the sentence ends with any kind of punctuation. It does not work however when the sentence is at the end of the text without any punctuation.
This is my current expression:
[^.?!]*(?<=[.?\s!])string(?=[\s.?!])[^.?!]*[.?!]
Works for:
This is a sentence with string. More text.
Does not work for:
More text. This is a sentence with string
Is there any way to make this word as intended? I can't find any character class for "end of text".
End of text is matched by the anchor $, not a character class.
You have two separate issues you need to address: (1) the sentence ending directly after string, and (2) the sentence ending sometime after string but with no end-of-sentence punctuation.
To do this, you need to make the match after string optional, but anchor that match to the end of the string. This also means that, after you recognize an (optional) end-of-sentence punctuation mark, you need to match everything that follows, so the end-of-string anchor will match.
My changes: Take everything after string in your original regex and surround it in (?:...)? - the (?:...) being a "non-remembered" group, and the ? making the entire group optional. Follow that with $ to anchor the end of the string.
Within that optional group, you also need to make the end-of-sentence itself optional, by replacing the simple [.?!] with (?:[.?!].*)? - again, the (?:...) is to make a "non-remembered" group, the ? makes the group optional - and the .* allows this to match as much as you want after the end-of-sentence has been found.
[^.?!]*(?<=[.?\s!])string(?:(?=[\s.?!])[^.?!]*(?:[.?!].*)?)?$
The symbol for end-of-text is $ (and, the symbol for beginning-of-text, if you ever need it, is ^).
You probably won't get what you're looking for with by just adding the $ to your punctuation list though (e.g., [.?!$]); you'll find it works better as an alternative choice: ([.?!]|$).
Your regex is way too complex for what you want to achieve.
To match only a word just use
"\bstring\b"
It will match start, end and any non-alphanum delimiters.
It works with the following:
string is at the start
this is the end string
this is a string.
stringing won't match (you don't want a match here)
You should add the language in the question for more information about using.
Here is my example using javascript:
var reg = /^([\w\s\.]*)string([\w\s\.]*)$/;
console.log(reg.test('This is a sentence with string. More text.'));
console.log(reg.test('More text. This is a sentence with string'));
console.log(reg.test('string'))
Note:
* : Match zero or more times.
? : Match zero or one time.
+ : Match one or more times.
You can change * with ? or + if you want more definition.
The input I can get might be
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22
or
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22/Demo.Tests/AverageTests.cs
I need to extract in both cases.
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22
Regex:
^(.*?)tags
is matching till
/DemoSystems/DemoFramework/MyRepo/MyModule/tags
And added complexity is that 2015_02_22 can be anything. A mix of number alphabets and whitespaces. Basically depends on developer. So in other words I have to match till 'tags' + the next folder after it.
Any pointers?
You can use:
.*?tags\/[^\/]+
It will match anything from the start of the line until the word tags, the / after the word tags and the following characters until another / (excluding that) or the end of the string.
Online demo
I have a simple regular expression looking for twitter style tags in a string like so:
$reg_exUrl = "/#([A-Za-z0-9_]{1,15})/";
This works great for matching words after an # sign.
One thing it does though which I don't want it to do is match full stops.
So it should match
"#foo"
but should not match
"#foo."
I tried adding amending the expression to dissallow full stops like so:
$reg_exUrl = "/#([A-Za-z0-9_]{1,15})[^\.]/";
This almost works, except it will not match if it's at the end of the string. EG:
It WILL match this "#foo more text here"
but won't match this "#foo"
Could anyone tell me where I'm going wrong?
Thanks
First of all your original expression can be written like the following:
/#\w{1,15}/
because \w is equivalent to [A-Za-z0-9_].
Secondly your expression doesn't match names with . so you probably meant that you don't want to match names ending with a dot and this can be done with the following:
/#\w{1,15}(?![^\.]*\.)/
Or if you want to match a name no matter how long it is just not ending with a dot then
/#\w+(?![^\.]\.)/
Oh ya, I forgot one thing, your problem was caused by the absence of any anchor characters such as the start of line ^ and end of line $, so you should use them if you want to match a string that contains only a twitter name which you wish to validate.
Summary: If you want to match names anywhere in the document don't use anchors, and if you want to know whether a given string is a valid name use the anchors.
It's not working if it's at the end of the string because it's expecting [^\.] after it.
What you are wanting, you can do with a negative lookahead to make sure there is no dot afterwards, like this:
/#([A-Za-z0-9_]{1,15})(?![^\.]*\.)/
Test it here
You could also do it this way:
/#([A-Za-z0-9_]{1,15})([^\.]*)$/
Test it here
This one allows for optional characters other than a dot, and then it has to be the end of the string.
A $ matches the end of the string, and for future reference, a ^ matches the begining:
$reg_exUrl = "/#([A-Za-z0-9_]{1,15})$/";
This seems like it should be trivial, but I'm not so good with regular expressions, and this doesn't seem to be easy to Google.
I need a regex that starts with the string 'dbo.' and ends with the string '_fn'
So far as I am concerned, I don't care what characters are in between these two strings, so long as the beginning and end are correct.
This is to match functions in a SQL server database.
For example:
dbo.functionName_fn - Match
dbo._fn_functionName - No Match
dbo.functionName_fn_blah - No Match
If you're searching for hits within a larger text, you don't want to use ^ and $ as some other responders have said; those match the beginning and end of the text. Try this instead:
\bdbo\.\w+_fn\b
\b is a word boundary: it matches a position that is either preceded by a word character and not followed by one, or followed by a word character and not preceded by one. This regex will find what you're looking for in any of these strings:
dbo.functionName_fn
foo dbo.functionName_fn bar
(dbo.functionName_fn)
...but not in this one:
foodbo.functionName_fnbar
\w+ matches one or more "word characters" (letters, digits, or _). If you need something more inclusive, you can try \S+ (one or more non-whitespace characters) or .+? (one or more of any characters except linefeeds, non-greedily). The non-greedy +? prevents it from accidentally matching something like dbo.func1_fn dbo.func2_fn as if it were just one hit.
^dbo\..*_fn$
This should work you.
Well, the simple regex is this:
/^dbo\..*_fn$/
It would be better, however, to use the string manipulation functionality of whatever programming language you're using to slice off the first four and the last three characters of the string and check whether they're what you want.
\bdbo\..*fn
I was looking through a ton of java code for a specific library: car.csclh.server.isr.businesslogic.TypePlatform (although I only knew car and Platform at the time). Unfortunately, none of the other suggestions here worked for me, so I figured I'd post this.
Here's the regex I used to find it:
\bcar\..*Platform
Scanner scanner = new Scanner(System.in);
String part = scanner.nextLine();
String line = scanner.nextLine();
String temp = "\\b" + part + "|" + part + "\\b";
Pattern pattern = Pattern.compile(temp.toLowerCase());
Matcher matcher = pattern.matcher(line.toLowerCase());
System.out.println(matcher.find() ? "YES" : "NO");
If you need to determine if any of the words of this text start or end with the sequence, you can use this regex: \bsubstring|substring\b:
anythingsubstring
substringanything
anythingsubstringanything
The simplest thing that you can do is:
dbo.*_fn$
It searches with dbo, followed by any characters, and then ends with _fn.
If you can identify what’s the right next character after n if it’s space, you can replace $ with space .