A doubt on REG EXP
Hi friends,
Please clarify the following doubt in Reg Exp.
Table EMP has following EMP_NAMEs:
============
Anand
Bala_G
Chitra
David_C
Elango
Fathima
============
We have a set of characters as "abcdefghijklmnopqrstuvwxyz0123456789".
Now we need to find the count of EMP_NAMES whose characters (any) are not in the list of characters in the above list. In this example, the result should be 2. i.e., 'Bala_D' and 'David_C'. The query should be like:
Declare
v_string varchar2(50) := 'abcdefghijklmnopqrstuvwxyz0123456789';
v_count number(6);
Begin
select count(*)
into v_count
from emp
where regexp_like(emp_name, v_string);
dbms_output.put_line(v_count);
end;
========================
Thanks in advance!
Hi,
Welcome to the forum!
To use REGEXP_LIKE, you could say:
WHERE REGEXP_LIKE ( emp_name
, '[^abcdefghijklmnopqrstuvwxyz0123456789]'
)However, it will be faster not to use regular expressions:
WHERE LTRIM ( emp_name
, 'abcdefghijklmnopqrstuvwxyz0123456789'
) IS NOT NULLEdited by: Frank Kulash on Oct 10, 2012 4:18 PM
Removed extra single-quote, after DAMorgan, below.
Similar Messages
-
How to make Matcher stop once a reg exp match is found
Is there a way to make the regular expression Matcher stop reading from the underlying CharSequence once it finds a match? For example, if I have a very long String and a match for some regular expression is at the beginning of the String, can I make the Matcher object stop examining the String once it finds the match? The Matcher object seems to always examine the entire CharSequence, even if a match is very near the beginning.
Thanks,
Zach Cox
[email protected]Nope, {1}+ doesn't work either. I know it's
continuing because I created my own CharSequence
implementation that just wraps a String orwhatever,
and I print to System.out whenever Matcher callsthe
charAt method.What about the lookingAt() method?I think lookingAt is like matches, except just the beginning of the CharSequence has to match (i.e. starting at index 0), not the entire thing. I tried it and it doesn't even find the reg exp. The find method at least finds the reg exp, it just reads too far. -
Not often I ask questions myself, and perhaps my mind's just gone fuzzy this morning, but I'm having trouble doing a simple replace with regular expressions...
In the below example I just want to replace all occurences of "fred" with "freddies"...
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', 'fred', 'freddies') from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFREDRECORD'
this freddiesdies is freddies freddies recordbut, obviously, I don't want the existing "freddies" to become "freddiesdies", it should stay as it is. So if I check for spaces either side of the search string (and take account of it maybe being at the start/end of the string...
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', '(^| )fred( |$)', '\1freddies\2') from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFRE
this freddies is freddies fred record
SQL>It no longer replaces the "freddies" incorrectly, BUT it only replaces the first occurence of "fred" with "freddies" and not the latter one. ?!?!?!
If I put an extra space inbetween the two "fred"s then it works:
SQL> ed
Wrote file afiedt.buf
1* select regexp_replace('this freddies is fred fred record', '(^| )fred( |$)', '\1freddies\2',2) from dual
SQL> /
REGEXP_REPLACE('THISFREDDIESISFREDFREDRECO
this freddies is freddies freddies record
SQL>But I'm not going to have double spaces between the words and I can't determine where to insert them to make it work like this so it's not a feasible solution, although it does seem to highlight that the regular expression parser is not taking the space after the first match in the context of being the space before the second match.
Is that a bug in the regular expression parser, a feature of the way regular expressions work (i.e. expected) or am I doing something wrong with my search and replace reg.exp. strings?
CheersI think this will explain ..
SQL> select regexp_replace
2 ('this freddies is fred fred fred record',
3 '(^| )(fred)($| )','\1freddies\3') str
4 from dual
5 /
STR
this freddies is freddies fred freddies record
1 row selected. -
Reg Exp always returning false value
Hi,
Below is my code. I want to restrict the values to only alphabets and numbers and not special char.
But the below condition fails on a positive value also. Ex: ABCD, abcd, 1234. These should be acceptable.
Is the reg exp wrong?
private var special_char:RegExp = /^[A-Za-z0-9]*$/;
private function validateSpecialChar(inputValue:String):Boolean {
if (special_char.test(inputValue))
valid = true;
else
valid = false;
return valid;
Thanks,
ImranTry: http://stackoverflow.com/questions/9012387/regex-expression-only-numbers-and-characters
-
Reg Exp won't make a match with metacharacters?
Hi All,
I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
thanks!
package dbmanager2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
* @author nkelleh
public class LotDialog
// Declare variables
private String[] dirFiles;
// Class constructor
public LotDialog(String path, String name)
// Create new file object based on path name given
File dir = new File(path);
// Assign file names to string array
dirFiles = dir.list(new stdfFilter(name));
public void printFiles()
for (String files : dirFiles)
System.out.println("File is " + files );
class stdfFilter implements FilenameFilter {
Pattern pattern;
public stdfFilter(String search)
// Replace wildcard, '*', with reg exp, '.*'
search = search.replaceAll("\\*", ".*");
search = search.replaceAll("\\?", ".");
pattern = Pattern.compile(search);
System.out.println(pattern.pattern());
public boolean accept(File dir, String name)
if (new File(dir,name).isDirectory())
return false;
else
// Return true if a match is found
Matcher matcher = pattern.matcher(dir.getName());
return matcher.matches();
}LeWalrus wrote:
Hi All,
I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
...Try debugging your code. A good place to start is to print the following to see where things go wrong:
public boolean accept(File dir, String name)
if (new File(dir,name).isDirectory())
System.out.println("Ignoring: "+new File(dir,name));
return false;
else
Matcher matcher = pattern.matcher(dir.getName()); // shouldnt that be 'name' instead of 'dir'?
System.out.println("Accept: "+dir.getName()+"? "+matcher.matches());
return matcher.matches();
} -
Hi Folks;
I need to create a reg exp pattern with these rules :
mpexprfinal : mpexprUnit(\ OROP\ mpexprUnit)*
mpexprUnit : mp(\ AND\ mp)*minusplusexpr
minusplusexpr : "\ \(+\)\ " or "\ \(-\)\ "
mp : "[A-Z]{1}[0-9]{6}" (ex: I123456)
OROP : ","
Help me please!
Edited by: Moostiq on 2 mai 2011 16:52
Edited by: Moostiq on 2 mai 2011 16:52Hi,
I don't know of any really good way to assign names to sub-patterns in a regular expression, and then use those names in bigger expressions.
You can (sort of) do the same thing in SQL, by assigning column aliases to string literals (as in def_1, below), or concatentions of literals and previouslly defined aliases (as in def_2):
WITH def_1 AS
SELECT '\(\+|-\)' AS minusplusexpr
, '[A-Z]{1}[0-9]{6}' AS mp
, ';' AS orop
FROM dual
, def_2 AS
SELECT def_1.*
, mp || '( AND '
|| mp
|| ')*' AS mpexprunit
FROM def_1
SELECT x.*
FROM table_x x
CROSS JOIN def_2 d
WHERE REGEXP_LIKE ( x.txt
, d.mpexprunit || '('
|| d.orop
|| '|'
|| d.mpexprunit
|| ')*'
;Take this as pseudo-code. I'm not sure it will do anything. (I can't test it until you post some sample data).
If it does run, I'm not sure it will do what you want (since you haven't explained what you want).
You may find it easier just to repeat the expressions in your code. An approach like the one above is most useful when the definitions (mp, mpexprunit, and so on) change frequently.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. I'm not sure you'll need any features that were added after Oracle 10.1, but why take a chance? -
Reg Exp confusion when searching for a '(' char
Hello,
I am trying to extract the name from the following HTML.
onclick="searchCitationAuthor('Inoue, K.', true);">I want to be able to extract 'Inoue, K.'.
My regular expression is as follows.
"\\=true\\)\">([^<]+)</a>";I need to extract from the entire line of code. I need to extract from the =true chars as this makes the Reg Exp distinctive.
I think the ')' char is confusing things.
Can anyone suggest anything?
Message was edited by:
VanJay011379
Sorry, I realize i was missing a ';' char. I thought the "\\)" was causing problems. Move on, nothing to see here LOL : )why not
String regex = "searchCitatationAuthor\\s*\\(\\s*'([^']*)'"
where is =true coming in though? -
Hi
I want to extract the first token of filename (and not the directory path) from a string like this:
D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
/HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
the tokens would bed HG-ORA02 in all instances
Could you help me creating a reg expression to get the token?
best regards
MetteHi,
Whenever you have a problem, it helps if you post your sample data in a form people can use.
CREATE TABLE and INSERT statements are great; so is:
CREATE TABLE table_x
AS select 'D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 1 as x_id FROM dual
UNION ALL SELECT 'HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 2 as x_id FROM dual
UNION ALL SELECT '\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 3 as x_id FROM dual
UNION ALL SELECT '/HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
AS filename, 4 as x_id FROM dual
;It also helps if you explain how you get the results you want from that data.
Assuming that
(a) the filename is divided, first, by '/' or '\' characters, and
(b) each of those parts may be divided into tokens by '.' or '#' characters, and that
(c) we want the first (b) part of the last (a) part:
SELECT REGEXP_SUBSTR ( REGEXP_SUBSTR ( filename
, '[^/\]*$'
, '[^.#]+'
) AS token_1
FROM table_x;Here, the inner REGEXP_SUBSTR finds the last part delimited by / or \. You can add other delimiters by putting them in the square brakets, anywhere after ^.
The outer REGEXP_SUBSTR operates on the results of the inner one. It returns the first part delimited by . or #. Again, you can add other delimiters. -
Hello,
I need some help on reg expressions.
I want to allow users to type a url on my html page. The way I currently handle this situations is this:
myString = myString.replaceAll("(?:https?|ftp)://\\S+(?<![,.?!)])", "<a href=\"$0\">$0</a>");
so when the user types in a url such as http://www.java.sun it would display it back as a url that he/she can click on. This part works fine
However, if the user types in something like this:
<img src="http://www.someUrl.com/img.gif"/> it fails. In this case the user should see the image but he/she does not.
How can I make sure that only those instances get replaced where only URL is typed which is not part of other html. Should I add blank spaces before and after the url?
Thank you.Will there be any links in the source document that are already in the processed format? That is, http://www.somewhere.org/If so, you'll need to match the whole element so don't accidentally match a URL within it. Then you can deal with the situation you brought up, where a start tag has a URL attribute. For that, just match any complete start tag and plug it back in. That should take care of any URL's that are contained within larger structures, leaving only "naked" URL's that need to be processed.
A simple replaceAll() won't work here, because you're doing different things with the text depending on what was matched. The Matcher class provides lower-level operations that let you do that kind of thing, but Elliott Hughes has written a nice little utility called Rewriter that does most of the work for you. Here's how you might use it: String regex = "(?is)" // CASE-INSENSITIVE and DOTALL modes
+ "<a\\s[^>]++>.*?</a>" // a complete A element
+ "|" // or
+ "<[a-z]+\\s[^>]++>" // a start tag with attributes
+ "|" // or
+ "(?:https?|ftp)://\\S+(?<![,.?!)])"; // a URL
Rewriter rewriter = new Rewriter(regex)
public String replacement()
String found = group(0);
return found.startsWith("<") ? found :
"<a href=\"" + found + "\">" + found + "</a>";
String resultStr = rewriter.rewrite(args[0]); -
Strange behavior when searching a phrase using reg exp and dynamic sql
Hi,
I have a strange issue while using dynamic sql for an apex page. I have a requirement to search a string in the database column which is entered by user on a page item. The search process should search the whole phrase only.
I have a query generated dynamically in the back end and use it in a cursor in the stored procedure
SELECT t.group_cn , t.group_desc, t.group_type, t.partner_organization_id, t.partner_organization
FROM vr_idm_group t WHERE regexp_like(t.group_desc,'(^|\W)HR Selection & Assignment(\W|$)', 'i')The pl sql code with the dynamic sql statements are below.
IF p_search_process NOT in ('PARTNER') THEN
OPEN v_cursor FOR v_sql;
ELSE
OPEN v_cursor FOR v_sql USING p_search_id;
END IF;
LOOP
FETCH v_cursor INTo v_obj.group_cn, v_obj.group_desc, v_obj.group_type, v_obj.partner_organization_id,
v_obj.partner_organization, v_obj.match_count;
EXIT WHEN v_cursor%NOTFOUND ;
v_search_array.extend;
v_search_array(v_search_array.last) := v_obj;
dbms_output.put_line(v_sql);
END LOOP;The search works fine if the search string does not contain any special character like &,- etc.
However, if the search string contains any special character, it does not return any thing. This strange issue happens only if I call the procedure from the apex page and the search string contains a special character. (please note that the procedure works fine even from apex if the string does not have a special character). When I debugged this, found that, the cursor does not fetch any rows (it is supposed to fetch two rows) for unknown reason. When I run the query separately, it returns the two rows (in which the column group_desc contains the search string "HR Selection & Assignment") as desired. Also, when I test the procedure in the back end (PLSQL developer), it works fine.
Any idea, what is causing this strange behaviour?
Advance thanks.
Regards,
Natarajani don't see anything about a dataProvider. you're assigning a source for a scrollpane. scrollpane's don't have a dataProvider property.
anyway, other than arrayRun always being false when that last if-statement executes, what's the problem? doesn't that movieclip display when that 2nd branch of the last if-statement executes (assuming instance is defined correctly etc)? -
Explanation of my reg exp code
Hi,
When I run my code below, the line:
Seat 4: playafly299 ($10 in chips)
results in a match, but
Seat 6: WillRyker ($5.55 in chips)
results in a miss. Can someone explain why? I read the pattern below as:
String literal Seat followed by one or more digits followed by colon followed by space followed by anything followed by space followed by character literal '(' followed by character literal '$' or nothing, followed by one or more digits followed by character literal '.' and one or more digits, OR nothing followed by string literal in chips. Am I missing something? Please help.
String patternStr = "Seat (\\d+): (.+) \\(\\$?(\\d+[\\.\\d+]?) in chips\\)";
Pattern p = Pattern.compile(patternStr);
Matcher m = p.matcher(currentLine);
if ( m.find() ) {
System.out.println("MATCH:" +currentLine);
Table t = h.getTable();
int seat_num = Integer.parseInt(m.group(1));
String player_name = m.group(2);
double chip_stack = Double.parseDouble(m.group(3));
System.out.println("CREATING PLAYER: " +player_name+ " with stack: " +chip_stack);
Player player = new Player(player_name, chip_stack);
t.setPlayerAtSeat(seat_num, player);
} else {
System.out.println("MISS: " +currentLine);
}Konigs wrote:
Thank you Sabre. When are the other brackets appropriate?The square brackets are used to define a set of characters (not a sequence) and the () brackets define a group. You have an optional group that includes the decimal point so you need () not [] . -
We have followed the recommendation to convert the cache database from Derby to MSSQL.
There seems to be an un-documented disadvantage in this:
regular expressions are no longer supported in filters !
Can anyone confirm this ?
We are running TES 6.1.0 with MSSQL 2008 database.you can try a combination of instr() and substr() function. the example below is using an instr() function to determine the position of the last comma that is used in the string. the substr() function takes cares of the getting the last word that is used in the string with the help of the instr() function.
SQL> select substr(a.str,instr(a.str,',',-1)+1) last_string
2 from (select 'abcd,def,hijk,lmno,pqrs' str from dual) a ;
LAST_STRING
pqrs
SQL> -
Oracle sql to outer join based on reg exp
Hi,
I am expecting output like (3). I want to join two tables with regex. join condition
. For example, in table1.string(abcYYMMDD.txt) I want to match date part (YYMMDD) wit any possible number in Table2.string (abc150420.txt)
Please suggest.
(1) table1:
abcYYMMDD.txt
ddefYYMMDD.txt
ghiYYMMDD.txt
(2) table2:
abc150420.txt
abc150421.txt
abc150422.txt
abc150320.txt
ddef150101.txt
ddef150404.txt
(3) Table1 left join Table2 (join example - abc(replace YYMMDD by regex).txt=abc150420.txt)
abcYYMMDD.txt,abc150420.txt
abcYYMMDD.txt,abc150421.txt
abcYYMMDD.txt,abc150422.txt
abcYYMMDD.txt,abc150320.txt
ddefYYMMDD.txt,ddef150101.txt
ddefYYMMDD.txt,ddef150404.txt
ghiYYMMDD.txt,The audittime field is a timestamp field.
If I give the below query, rownum is not in the sequential order, see below few records..
SELECT rownum,to_char(audit_time_stamp,'dd-mon-yyyy HH24:MI:SS.FF') from audit_details ORDER BY audit_time_stamp
ROWNUM to_char(audit_time_stamp,'dd-mon-yyyy HH24:MI:SS.FF')
16 18-apr-2007 14:30:52.551010
17 18-apr-2007 16:33:21.900305
18 18-apr-2007 17:49:44.061420
19 18-apr-2007 17:49:44.134804
20 19-apr-2007 16:40:15.775235
21 22-apr-2007 23:31:01.818784
ROWNUM To_char(audit_time_stamp,'dd-mon-yyyy HH24:MI:SS.FF')
1 01-may-2007 19:17:46.880342
2 01-may-2007 19:24:04.952571
3 01-may-2007 19:24:32.182110
4 01-may-2007 19:25:49.464260
5 01-may-2007 19:25:52.127018
6 01-may-2007 19:27:34.099095
7 01-may-2007 19:30:34.763481
8 01-may-2007 19:31:06.226955
9 01-may-2007 19:32:36.727196
10 01-may-2007 19:40:44.061941 -
Handling '\' in reg exp query while integrating it in phython
Hi,
I am using the oracle 10g . I am trying to write a below mention sql regular expression in Python script. This query is working fine when I am running this in the sql developer (using it independently) However when I am trying to integrate the same inside Python script it doesn't do the required job. As per my Initial analysis this may be because in my regex query I have use '\' (in bold) which it is escaping because in log it is getting replaced by ^
Actual Query_
query = "UPDATE "+self.schema+";."+table_name+" SET SSR_FREE_TEXT=REPLACE(REGEXP_REPLACE(:1,'(\d{6})(\d{2,9})(\d{4})','\1X\3'), 'X', LPAD('X',LENGTH(SSR_FREE_TEXT) - LENGTH(REGEXP_REPLACE(SSR_FREE_TEXT,'(\d{6})(\d{2,9})(\d{4})','\1\3')),'X')) WHERE SSR_ID=:2"
In log_
UPDATE OWNADSSMOHANTHY_AIR_AY.SSR SET SSR_FREE_TEXT=REPLACE(REGEXP_REPLACE(:1,'(\d{6})(\d{2,9})(\d{4})','^AX^C'), 'X', LPAD('X',LENGTH(SSR_FREE_TEXT) - LENGTH(REGEXP_REPLACE(SSR_FREE_TEXT,'(\d{6})(\d{2,9})(\d{4})','^A^C')),'X')) WHERE SSR_ID=:2
The use of this regexp is IF I have a value of IDCCCA5475129999998943 it should be replaced to IDCCCA547512XXXXXX8943
Whereas when using in python it replaced the value to IDCCCAXXXXXXXXXXXXXXXX
Could you please help me in resolving this
RegardsI do not know much about Python but can you look into this line:
Other programming languages like .NET languages, Java, and Python instead provide regular expressions through standard libraries.
Please refer:
http://en.wikipedia.org/wiki/Regular_expression -
[JS] Reg Exp Error when using *
Hello everyone,
I get a syntax error when executing a script which contains RegExp handling strings with "*".
ie:
var x = /\*\*\*ABC/;
alert (RegExp(x)); //*** WORKS because x is defined as an EXPRESSION
var x = "\*\*\*ABC";
alert (RegExp(x)); //*** SYNTAX ERROR when executing
var x = "***ABC";
alert (RegExp(x)); //*** SYNTAX ERROR when executing
My problem is I have to build the expression using strings. So I was hoping to concatenate the string portionsa and use New RegExp to create my expression. Unfortunately, if we have STARS (*) in the string you get an error. Which as forced me to HARDCODE and I whish not to.
ie:
alert (yyy.search(/\*\*\*ABC/);
FYI: I have expample in HTML where ".value" is used. But it does not work w/ InDesign???
ie:
var re = new RegExp(document.demoMatch.regex.value);
if (document.demoMatch.subject.value.match(re))
alert("Successful match");
else
alert("No match");
Any suggestions?Yes it works!!!
To look for 3 stars and "ABC", I have to define like this
var a="\\*\\*\\*ABC";
var patt1=new RegExp(a);
alert(patt1.test("abcd*ABCefg"));
So when I build the string I have to use 2 backslashes!!!
Thank you so much.
FYI: Using ".source" work too. Still working on how to add a flag (/i)
var y = "xxx***ABCyyyxxx***ABCyyyxxx***ABCyyy";
var x = /\*\*\*/;
var x = new RegExp(x.source + "ABC");
alert (RegExp(x));
var z = x.exec(y);
if (z != null)
alert ("Found at position "+z.index+"\nHow many: "+z.length);
var z = y.match(x);
if (z != null)
alert ("Found at position "+z.index+"\nHow many: "+z.length);
Maybe you are looking for
-
Open Sales Order table with multiple schedule line....
YUSUF BHORI wrote: Hi Experts, In Sales Order there are multiple schedule line for single item. Where and in which table i can find open qty for order ,material, item and schedule line items. I Want open items for each schedule line. For One vbeln, p
-
1) what are the ALE settings i have to maintain in R/3 system and XI in Idoc 2 file scenario?(I know little bit RFC Destination, Port, Partner profile in R/3 system. is it required to maintain the port in XI also? ) 2) what is use of Meta data ( ID
-
Error in Message Alert /SCOT
Hi All, I have configured the alert Message in the development and also in the Quality , In development it is working fine but in the Quality i am not able to get the mails in my inbox. Here are the few things that i have configured: 1. Created a
-
Hi everyone, See if any of you can ans my question which has been bothering me for 2 week, very very annoying ...... 1) I created an USPS priority international label through paypal, sent the parcel, and it was stucked in LA, then return back to
-
Group Policy not coming down on some machines
Environment: Client 4.83SP1 Windows 2k SP4 Netware 5.1 eDir 8.7.3 Zen 3.2 Symptom: After several agonizing days of going through the TIDs and turning on debugging and checking all file dates on the workstation in question, a working laptop and the pu