I am trying to search all the registry keys and check the data if there is any jre1.5.0_14. I wonder how can I match jre1.5.0_14 via regex?
Thanks in advance.
Best Regards.
There is no point in using regular expressions when you're looking for a particular (sub)string. String functions provide better performance in that scenario:
If InStr(str, "jre1.5.0_14") > 0 Then
'do something
End If
Regular expressions are useful when you want to match a variety of (sub)strings, for instance JRE 1.5 updates 14 through 17:
Set re = New RegExp
re.Pattern = "jre1.5.0_1[4-7]"
If re.Test(str) Then
'do something
End If
Related
First time posting, and need a little help with a regex match I'm trying to come up with.
Here is the format I have
|user|DOMAIN\user|
I'm trying to write a regex match that will only capture the username, and then only capture the domain.
My thought process is to first match all the text and then create (3) groups? based on that I would have the information I'm looking for.
Suggestions? Examples?
Using non-greedy quantifiers helps a lot in readability here:
set data {|glenn|JACKMAN\glenn|}
regexp {^\|(.*?)\|(.*?)\\} $data -> user domain
puts "$user:$domain"
outputs
glenn:JACKMAN
You're looking for a regex like this:
\|([^|]+)\|([^\]+)\\([^|]+)\|
You can see it in action here: http://refiddle.com/2we4
If you do not have a constraint to use regex match, I would suggest that you go with splitting the string at pipes. This way, your first or second token (depending on how the given language treats an empty token before first pipe) will be user. Now you can remove the [length(user) + 1] substring from end of the next token. This would provide you with the DOMAIN.
Note that the assumption here is, that user or DOMAIN do not contain any pipe character (|).
This is also another option for matching the username and domain.
% set data {|glenn|JACKMAN\glenn|}
|glenn|JACKMAN\glenn|
% regexp {^\|([^|]+)\|([^\]+).*} $data m a b
1
% puts "--- a $a ----b $b----"
--- a glenn ----b JACKMAN----
Another way for exact match.
% regexp {^\|([A-z]+)\|([A-z]+)\.*} $data m a b
1
% puts "match $m--- a $a ----b $b----"
match |glenn|JACKMAN\glenn|--- a glenn ----b JACKMAN----
I am trying to get likers for some artists through an index on Name :
START n=node:Artist(Name =~ 'Michael*.')
MATCH n<-[:LIKES]-liker
return liker.Id, n.Label
LIMIT 50
And I have this error :
Invalid query
string literal or parameter expected
"START n=node:ArtistId(Name =~ 'Michael*.')"
I am wondering how can I use regex in index query?
I know I can use regex in match but I don't know how can I use regex in START.
Thanks for your help
You can't use normal regex syntax, but you can use wildcards:
START n=node:Artist('Name:Michael*')
Edit:
Neo4J uses Apache Lucene for index queries. You have a few other cool things you can do in addition to wildcards.
I'm somewhat new to ruby and have done a ton of google searching but just can't seem to figure out how to match this particular pattern. I have used rubular.com and can't seem to find a simple way to match. Here is what I'm trying to do:
I have several types of hosts, they take this form:
Sample hostgroups
host-brd0000.localdomain
host-cat0000.localdomain
host-dog0000.localdomain
host-bug0000.localdomain
Next I have a case statement, I want to keep out the bugs (who doesn't right?). I want to do something like this to match the series of characters. However, it starts matching at host-b, host-c, host-d, and matches only a single character as if I did a [brdcatdog].
case $hostgroups { #variable takes the host string up to where the numbers begin
# animals to keep
/host-[["brd"],["cat"],["dog"]]/: {
file {"/usr/bin/petstore-friends.sh":
owner => petstore,
group => petstore,
mode => 755,
source => "puppet:///modules/petstore-friends.sh.$hostgroups",
}
}
I could do something like [bcd][rao][dtg] but it's not very clean looking and will match nonsense like "bad""cot""dat""crt" which I don't want.
Is there a slick way to use \A and [] that I'm missing?
Thanks for your help.
-wootini
How about using negative lookahead?
host-(?!bug).*
Here is the RUBULAR permalink matching everything except those pesky bugs!
Is this what you're looking for?
host-(brd|cat|dog)
(Following gtgaxiola's example, here's the Rubular permalink)
I made an article spinner that used regex to find words in this syntax:
{word1|word2}
And then split them up at the "|", but I need a way to make it support tier 2 brackets, such as:
{{word1|word2}|{word3|word4}}
What my code does when presented with such a line, is take "{{word1|word2}" and "{word3|word4}", and this is not as intended.
What I want is when presented with such a line, my code breaks it up as "{word1|word2}|{word3|word4}", so that I can use this with the original function and break it into the actual words.
I am using c#.
Here is the pseudo code of how it might look like:
Check string for regex match to "{{word1|word2}|{word3|word4}}" pattern
If found, store each one as "{word1|word2}|{word3|word4}" in MatchCollection (mc1)
Split the word at the "|" but not the one inside the brackets, and select a random one (aka, "{word1|word2}" or "{word3|word4}")
Store the new results aka "{word1|word2}" and "{word3|word4}" in a new MatchCollection (mc2)
Now search the string again, this time looking for "{word1|word2}" only and ignore the double "{{" "}}"
Store these in mc2.
I can not split these up normally
Here is the regex I use to search for "{word1|word2}":
Regex regexObj = new Regex(#"\{.*?\}", RegexOptions.Singleline);
MatchCollection m = regexObj.Matches(originalText); //How I store them
Hopefully someone can help, thanks!
Edit: I solved this using a recursive method. I was building an article spinner btw.
That is not parsable using a regular expression, instead you have to use a recursive descent parser. Map it to JSON by replacing:
{ with [
| with ,
wordX with "wordX" (regex \w+)
Then your input
{{word1|word2}|{word3|word4}}
becomes valid JSON
[["word1","word2"],["word3","word4"]]
and will map directly to PHP arrays when you call json_decode.
In C#, the same should be possible with JavaScriptSerializer.
I'm really not completely sure WHAT you're asking for, but I'll give it a go:
If you want to get {word1|word2}|{word3|word4} out of any occurrence of {{word1|word2}|{word3|word4}} but not {word1|word2} or {word3|word4}, then use this:
#"\{(\{[^}]*\}\|\{[^}]*\})\}"
...which will match {{word1|word2}|{word3|word4}}, but with {word1|word2}|{word3|word4} in the first matching group.
I'm not sure if this will be helpful or even if it's along the right track, but I'll try to check back every once in a while for more questions or clarifications.
s = "{Spinning|Re-writing|Rotating|Content spinning|Rewriting|SEO Content Machine} is {fun|enjoyable|entertaining|exciting|enjoyment}! try it {for yourself|on your own|yourself|by yourself|for you} and {see how|observe how|observe} it {works|functions|operates|performs|is effective}."
print spin(s)
If you want to use the [square|brackets|syntax] use this line in the process function:
'/[(((?>[^[]]+)|(?R))*)]/x',
Given that I have a string such as
"Donald Trump <donald#trump.com>"
"Art Job <art#job.com>"
How can I find every row that contains "donald#trump.com" using MongoDB in Rails?
Thanks
From the documentation:
search_string = params['search']
# Constructor syntax coll.find({"name" => Regexp.new(search_string)})
# Literal syntax coll.find({"name" => /#{search_string}/})
Beware though... You can't use an index with this query since your regex isn't anchored to the front of the string.
You can perform such a search only using regular expressions:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
In your case you won't be able to search in a efficient way except you denormalize your data and store your email addresses in a dedicated attribute of the document.
No idea about Ruby but every driver should have support for regular expressions.