I'm currently learning how to use web developer tools. So as a part of it I'm trying to find some multiple keywords at the search box which appears after pressing ctrl + F
My question is
How can I apply multiple search filters at a time uisng find. Like If i want to find more than 2 keywords in a source what is the best way to do it.
I've tried using regular expressions like so(I'm pretty sure syntax is wrong)
'Keyword1' & 'Keyword2'
Also tried
'Keyword1' | 'Keyword2'
Also tried
'Keyword1' or 'Keyword2'
But No use. I'm I missing anything here? I know we can use regular expressions but I'm looking for syntax to search multiple keywords. I'm pretty sure I've once used it a while ago . I don't remember exact expression to do so..
Using regex search, you can do: ^(?=.*foo)(?=.*bar).*$.
Source: https://stackoverflow.com/a/37692545/6911703
The syntax is
keyword1|keyword2|keyword3
without spaces and quotations
In my machine first I needed to turn off the regex feature before searching, and than turn it on again. o.w. it got stucked
Related
Ok so the main problem is a poorly designed php script.. but I cant do any thing about that right now..
So I turn to you for some help! :)
I want to list all items that start with "a%".. easy!.. well not here.. by default the search is made with wildcards "%string%".
SELECT DISTINCT `Select2` FROM `items` WHERE `Select2` LIKE "%a%"
And I canĀ“t change the search script... :/
Is there anyway that you can think of to get me around this problem?
There is no way to get around something hardcoded like that. But, since the results will include the results you are looking for, as well as substring matches, you can filter out the substring matches on the application side.
I would like to query a single column (varchar):
sample datarows:
1) The fox jumps like a foo on my bar
2) Jumpers are not cool
3) Apple introduced iJump
When I enter a search criteria like... jump
I expect to get a resultset of: jumps, Jumpers, iJump
(So I dont want the complete row)
Currently I'm using MySQL (I'm open to suggestions as long it's open source)
Since you're using MySQL, I might suggest looking into LIB_MYSQLUDF_PREG.
This open source library will provide you with additional regex functionality, including the PREG_CAPTURE function, which extracts a regex match from a string.
Using this function, you could easily build a regex to return the match you're looking for... Something like:
\b\w*jump\w*\b
Getting any row with your search criteria is easy:
SELECT sentence
FROM sentences
WHERE sentence LIKE '%jump%'
I'd probably do the rest in application logic, since doing it in the database doesn't help you at all.
Also, any method of splitting a string and handling it will probably be database-specific, so you would need to say which one you're using.
In field post_content I have a string like this in nearly 800 rows:
http://somesite.com/">This is some site</a>
I need to remove everything from "> onwards so that it leaves just the URL. I can't do a straight find and replace because the text is unique.
Any clues? This is really my first foray into MySQL database modifications but I did do an extensive search before posting here.
Thanks,
~Kyle~
From this site: http://www.regular-expressions.info/mysql.html
LIB_MYSQLUDF_PREG
If you want more regular expression power in your database, you can consider using LIB_MYSQLUDF_PREG. This is an open source library of MySQL user functions that imports the PCRE library. LIB_MYSQLUDF_PREG is delivered in source code form only. To use it, you'll need to be able to compile it and install it into your MySQL server. Installing this library does not change MySQL's built-in regex support in any way. It merely makes the following additional functions available:
Here it comes...
PREG_CAPTURE extracts a regex match from a string. PREG_POSITION returns the position at which a regular expression matches a string. PREG_REPLACE performs a search-and-replace on a string. PREG_RLIKE tests whether a regex matches a string.
Sounds exactly what you're looking for.
All these functions take a regular expression as their first parameter. This regular expression must be formatted like a Perl regular expression operator. E.g. to test if regex matches the subject case insensitively, you'd use the MySQL code PREG_RLIKE('/regex/i', subject). This is similar to PHP's preg functions, which also require the extra // delimiters for regular expressions inside the PHP string.
See this post: How to do a regular expression replace in MySQL?
Either that or you could just write a script in any lanugage which goes through each record, does a regex replacement and then updates the field. For more info on regex, see here: http://www.regular-expressions.info/reference.html
There's a number of options. One might be to use SUBSTRING_INDEX():
UPDATE
table
SET field = SUBSTRING_INDEX( field, '">', 1 )
It's possible - there is a syntax for User Defined Functions which would let you pass in a regular expression pattern that matches the link and strips everything else.
However, this is quite complicated for somebody new to MySQL, and from your question, this sounds like a one-off. In which case - why not just use Excel and then reimport the data?
Great stuff!
All seems doable with a little bit of time and self education.
In the end, I exported that table as a CSV in Sequel Pro and did some nifty find and replace work in Coda. Not as sophisticated as your suggestions, but it worked.
Thanks again,
~Kyle~
I'm using sqlite3 to try and find users who have an e-mail address that is either with Gmail, Yahoo or Hotmail. It needs to do this just on the basis of the first part of the domain, so I want any address that had the #yahoo to be accepted.
It appears from documentation that it is not possible to use a regular expression when querying an sqlite database. Is there any elegant way of doing something similar? It doesn't seem to be possible to use a "like/in" with multiple options (eg: LIKE (%#yahoo%, %#gmail%, %#hotmail%)?
Failing that, I may switch over to MySQL for a reg exp as I want to keep the solution simple and elegant and DB isn't a major factor. How would said regexp query be written in MySQL?
You can't use multiple "LIKE" in that way but you can use:
(email LIKE "%#yahoo%" OR email LIKE "%#gmail%" OR ....)
you can use the way Nemoden is using or something like this (not tested)
WHERE email REGEXP '[\w\.]+#(yahoo|gmail|ymail|hotmail)\.(com|ru|co\.uk)'
This would be much faster because LIKE %string% OR ... is very slow and doesnt use any indexes(dont know if REGEXP uses indexes tho).
I think you might want something like this (RLIKE function):
WHERE email RLIKE '^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.([A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum|travel)$'
If you use whatever_cs (case sensitive collation), use a-zA-Z instead of A-Z.
You can also get rid of ^ and $ in the regex. ^ means "starts with" and $ means "ends with"
UPDATE:
'.*#(gmail|hotmail|yahoo)\.[A-Z]{2,4}'
Using full text search in mysql I'd like to have exact phrase:
"romantic dinner" to be found.
But I also would like each of the words could have synonyms like:
"romantic dinners" to be found for example (our language has great problem where every word has 8 endings like)...
I tried:
+"romantic (dinner dinners)" and
"romantic +(dinner dinners)"
but nothing seems to get results... Is it possible to make some logical OR inside exact search?
UPDATE: TO make it one sentance question: Is there a way to put some logical operators in exact match ("") in full text search?
It will only partially your problem, but there is a soundex() function in mysql which transform the given string to a soundex representation. Similars string should have the same soundex representation so it's maybe a start.
Hope this helps.
If '"roman* dinn*" doesn't work for you, it might be time to look into something like Solr: http://lucene.apache.org/solr/ which will allow for more sophisticated searches, and might already have a stemmer for your language.
SELECT field_name FROM table_name WHERE MATCH(field_name) AGAINST('romantic* dinner*' IN BOOLEAN MODE)...
definitely you can use + and - to further refining your results
reference: http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html