ActiveRecord: match fields that start with plus (+) - ruby-on-rails

I am trying to get all records where my phone field starts with a '+'
Company.where("phone LIKE ?", "+%") // RETURNS 0 RESULTS
and for some reason its listing zero results, even when there are results that start with '+'
I also tried to use a \ in order to escape the special meaning of '+' to no avail.
Although, if I try to match string that start with +1 for example, it works as expected.
Company.where("phone LIKE ?", "+1%") // WORKS FINE

Its the quotation marks!
Company.where("phone LIKE ?", '+%')
Using ' single quotes instead of " double-quotes, fixed the query.

Related

[splunk]: Obtain a count of hits in a query of regexes

I am searching for a list of regexes in a splunk alert like this:
... | regex "regex1|regex2|...|regexn"
Can I modify this query to get a table of the regexes found along with their count. The table shouldn't show rows with 0 counts.
regex2 17
regexn 3
The regex command merely filters events. All we know is each result passed the regular expression. There is no record or indication of why or how any event passed.
To do that, you'd have to extract a unique field or value from each regex and then test the resulting events to see which field or value was present. The regex command, however, does not extract anything. You'd need the rex command or the match function to do that.
Looks like | regex line is not needed. This is working for me. Notice the extra brackets.
| rex max_match=0 "(?P<countfields>((regex1)|(regex2)|..|(regexn)))"
| stats count by countfields

How to filter only percent symbol (%) in LIKE statement

There are three records in clientdataset
123+%1
123+%
123+&
I use the filter
DataSet.Filter := ' Column LIKE ''%123+%'' '
And the result show three records.
How can i filter to get item 1, 2 items instead of the third one?
Since "%" in SQL is usually used as a wildcard character, you will have to escape it if you want to search for the character itself.
So
DataSet.Filter := ' Column LIKE ''%123+\%%''
should do it.
The first "\%" escaped % means, it will be looking for the character itself, and the second one after that, that anything else ( in your example the "1") can come after that.

string concatenation in Cypher Neo4j

I want to achieve this: retrieve a word from a CSV file, then look for the existence of a hashtag with the word in a post the problem is that I was unable to perform the concatenation
The "Type mismatch" error could be solved by enclosing the concatenation in parentheses, as in:
WHERE line[0] =~ (".*#" + line[0] + ".*")
However, logically, that WHERE clause can never be true. A string cannot be equal to a longer string (itself, preceded by an extra character).
If you just trying to see if a word starts with a hashtag, this should work:
WHERE line[0] STARTS WITH "#"
Or, if you want to see if there is a hashtag in the string:
WHERE line[0] CONTAINS "#"

regular expression form to match string

I am using IOS regular expression engine to match any text in the form:
"[h1]test text[/h1]"
i wrote: #"\\[h1]([^.]*)[/h1\\]]"
to match this form, but it is working sometimes and other times it matches text out of bound of the last bracket, is it the best form to match these strings or what you suggest ?
I would recommend using (.*?) instead of ([^.]*?).
It looks want you want is "between [h1] and [/h1] match anything." That would be (.*?).
What you have is "between [h1] and [/h1] match anything which is not a period (.)."
In addition, you have a problem with your ending [/h1\\]] means end with a /, h, 1, or ]. I think you want \\[/h1] which means end with the string [/h1].
The final regex would be #"\\[h1](.*?)\\[/h1]".

fuzzy search using cypher

I have node for user with FirstName, LastName properties. Now I want to search some value in both properties from both site. Let I have to explain.
FirstName LastName
--------- --------
Manish Pal
Pal Dharmesh
Rajpal Yadav
sharma shreepal
Now I want to search which node's firstname or lastname contain 'pal'.
I have written query like this.
START users=node(*)
WHERE (users.FirstName =~ '(?i)pal.*' OR users.LastName =~ '(?i)pal.*')
RETURN users;
It gives me just 2 nodes, but I want all node with is containing 'pal'
If I try like this
START users=node(*)
WHERE (users.FirstName =~ '(?i)*.pal.*' OR users.LastName =~ '(?i)*.pal.*')
RETURN users;
It is giving me following error.
"PatternSyntaxException"
Dangling meta character '' near index 4 (?i).ant. ^*
I have set example here for your ready reference.
Thanks.
The second query contains invalid regular expression syntax. I think you mean:
START users=node(*)
WHERE (users.FirstName =~ '(?i).*pal.*' OR users.LastName =~ '(?i).*pal.*')
RETURN users
Note the difference to the query in your post:
'(?i)*.pal.*' in your post, and
'(?i).*pal.*' in the above query
The asterisk * means the expression before me [the asterisk] may appear an arbitrary number of times, including zero. But (?i) is no regular expression but just a modifier to ignore the case of the actual expression. I think you meant .*. The regular expression . matches any character, the asterisk allows any character to appear an arbitrary number of times.
Thus, '(?i).*pal.*' says: [ignore case] <arbitrary number of any characters><the exact character sequence: "pal"><arbitrary number of any characters>
The above query returned four results for me:
users.FirstName | users.LastName
---------------------------------
sharma | shreepal
Rajpal | Yadav
Pal | Dharmesh
Manish | Pal
Which is what you wanted, if I understood your correctly.

Resources