I need a regex to select words from given list of words. - regex-lookarounds

Ex:
I have list like word1, word2, word3, word4.
I can select one or more words , but only within this four.
Pls tell the regex for this.

Finally I found something
^((man1|man2|man3|man4)(,(man1|man2|man3|man4)){0,3})?$
only problem is I cant restrict duplicating.
Any suggestion to restrict duplicating?????

Related

How do I exclude particular words from a match?

Suppose I have the following SQL query:
SELECT
id, text
FROM
comments
WHERE
lower(text) LIKE '%hell%'
ORDER BY len(text) ASC
This matches any text that contains hell. However, I want to exclude a particular word from a match: "seashells". How can I write an SQL query that matches everything that contains hell, but ignores seashells?
Examples:
He said hello to the boy — matches.
Are there seashells on the beach? — no match.
Unshelled seashells — matches.
You could try keeping your current logic but checking for%hell% after first removing seashells from the text:
SELECT id, text
FROM comments
WHERE LOWER(REPLACE(text, 'seashell', '')) LIKE '%hell%'
ORDER BY LEN(text);
Note that regex search would be a much better way to handle your requirement, but SQL Server does not have much built in regex support.
You can try
Not Like in Sql Query. Here is something you can try.
SELECT
id, text
FROM
comments
WHERE
lower(text) LIKE '%hell%'
ORDER BY len(text) ASC
EXCEPT
SELECT
id, text
FROM
comments
WHERE
lower(text) LIKE '%seashells%'
OR
lower(text) LIKE '%other_word%'
ORDER BY len(text) ASC
To exclude some specific key word containing hell .
Note: NOT / LIKE IS CASE SENSITIVE.

SQLite find words with two "a" letters

I'm trying to filter out words that have two letter "a"'s in them.
I've tried using LIKE, but can't figure out how to filter words with two "a"'s (they don't have to be consecutive).
SELECT Sanat.sana FROM Sanat WHERE Sanat.sana LIKE '%a%';
For exactly 2 a's you could do:
SELECT Sanat.sana FROM Sanat WHERE LENGTH(REPLACE(Sanat.sana, 'a', '')) = LENGTH(Sanat.sana) - 2;
You would use like:
WHERE Sanat.sana LIKE '%a%a%';
Note: This will generally also match upper-case 'a's.
"LIKE '%a%a%'" would also show words with more than 2 a's.
You could instead use something like this:
SELECT sana FROM Sanat WHERE sana LIKE '%a%a%' AND sana NOT LIKE '%a%a%a%';

PLSQL search string using LIKE backwards

I have a view which has VARCHAR2 column. The column contains a string
which is concatenation of 2 columns from a different table.
For example I search "James Smith".
I search the column using LIKE:
LOWER(USER_LIST.SEARCH_STRING) LIKE LOWER 'James Smith'
I get the results just fine.
I would like to know if there's an option to perform a reverse search (still using LIKE) and getting the same results, like so:
LOWER(USER_LIST.SEARCH_STRING) LIKE LOWER 'Smith James'
Please note that I'm aware that using regex or adding an additional column to the view can resolve this, but I wish to make as minimal changes as possible.
Thanks in advance.
I hope the below answer illustrates your requirement.
SELECT A.NM
FROM
(SELECT 'Avrajit Roy' nm FROM dual
)A
WHERE lower(A.NM) LIKE lower('avrajit roy')
OR TRIM(lower(SUBSTR(a.nm,instr(a.nm,' ',1)+1,LENGTH(a.nm))
||' '
||SUBSTR(a.nm,1,instr(a.nm,' ',1)))) LIKE lower('roy avrajit');

RegExp Find Numbers that have All Same Digits

I am working with an Oracle database and would like to write a REGEXP_LIKE expression that finds any number where all digits are the same, such as '999999999' or '777777777' without specifying the length of the field. Also, I would like it to be able to identify characters as well, such as 'aaaaa'.
I was able to get it working when specifying the field length, by using this:
select * from table1
where regexp_like (field1, '^([0-9a-z])\1\1\1\1\1\1\1\1');
But I would like it to be able to do this for any field length.
If a field contains '7777771', for example, I would not want to see it in the results.
Try this:
^([0-9a-z])\1+$
Live demo
You're almost there. You just need to anchor the end of the regex.
^([0-9a-z])\1+$

Difference between LIKE and NOT LIKE searching for alpha numeric data

What is the difference between these two statements as far as the results?
SELECT * FROM DTSEARCHER
WHERE word LIKE '%[^a-zA-Z0-9]%'
SELECT * FROM DTSEARCHER
WHERE word not LIKE '%[^a-zA-Z0-9]%'
in the first one, you will get anything that matches
in the second one, you will get the rest.