Reg exp question
Hi!
How to select from some VARCHAR column only printable characters?
Regards,
Psmakr
SQL> SELECT REGEXP_SUBSTR('AS11 sfd' || CHR(7) || 'xx', '[[:print:]]+') FROM dual;
REGEXP_SU
AS11 sfd
SQL>
Similar Messages
-
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
-
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? -
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. -
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. -
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();
} -
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? -
I issued the following command to backup all objects owned by msd.
exp msd/msd owner=msd file=/d1/dhurley/msd.dmp log=/d1/dhurley/msd.log \
compress=n direct=y recordlength=32768
The logfile is as follows
Connected to: Oracle8i Enterprise Edition Release 8.1.6.1.0 - Production
With the Partitioning option
JServer Release 8.1.6.1.0 - Production
Export done in WE8ISO8859P1 character set and WE8ISO8859P1 NCHAR character set
. exporting foreign function library names for user MSD
. exporting object type definitions for user MSD
About to export MSD's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export MSD's tables via Direct Path ...
. . exporting table MSD_BOOKING_DATA 0 rows exported
. . exporting table MSD_CURRENCY_CONVERSIONS 0 rows exported
. . exporting table MSD_DEMAND_PLANS 10 rows exported
. . exporting table MSD_DP_DIMENSIONS 60 rows exported
. . exporting table MSD_DP_EXPRESS_SETUP 9 rows exported
. . exporting table MSD_DP_HIERARCHIES 90 rows exported
. . exporting table MSD_DP_PARAMETERS 18 rows exported
. . exporting table MSD_DP_SCENARIOS 9 rows exported
. . exporting table MSD_DP_SCENARIO_ENTRIES 5568 rows exported
. . exporting table MSD_DP_SCENARIO_EVENTS 0 rows exported
. . exporting table MSD_DP_SCENARIO_INTRODUCTIONS 0 rows exported
. . exporting table MSD_DP_SCENARIO_OUTPUT_LEVELS 50 rows exported
. . exporting table MSD_EVENTS 0 rows exported
. . exporting table MSD_EVENT_DETAILS 0 rows exported
. . exporting table MSD_EVENT_PRD_DETAILS 0 rows exported
. . exporting table MSD_EVENT_PRODUCTS 0 rows exported
. . exporting table MSD_HIERARCHIES 9 rows exported
. . exporting table MSD_HIERARCHY_LEVELS 29 rows exported
. . exporting table MSD_INTRODUCTION_EVENTS 0 rows exported
. . exporting table MSD_INTRODUCTION_PLANS 0 rows exported
. . exporting table MSD_ITEM_LIST_PRICE 3 rows exported
. . exporting table MSD_LEVELS 29 rows exported
. . exporting table MSD_LEVEL_ASSOCIATIONS 71 rows exported
. . exporting table MSD_LEVEL_VALUES 61 rows exported
. . exporting table MSD_MFG_FORECAST 0 rows exported
. . exporting table MSD_SALES_FORECAST 0 rows exported
. . exporting table MSD_SALES_OPPORTUNITY_DATA 0 rows exported
. . exporting table MSD_SHIPMENT_DATA 755 rows exported
. . exporting table MSD_ST_BOOKING_DATA 0 rows exported
. . exporting table MSD_ST_CURRENCY_CONVERSIONS 0 rows exported
. . exporting table MSD_ST_ITEM_LIST_PRICE 0 rows exported
. . exporting table MSD_ST_LEVEL_ASSOCIATIONS 0 rows exported
. . exporting table MSD_ST_LEVEL_VALUES 0 rows exported
. . exporting table MSD_ST_MFG_FORECAST 0 rows exported
. . exporting table MSD_ST_SALES_FORECAST 0 rows exported
. . exporting table MSD_ST_SALES_OPPORTUNITY_DATA 0 rows exported
. . exporting table MSD_ST_SHIPMENT_DATA 0 rows exported
. . exporting table MSD_ST_TIME 0 rows exported
. . exporting table MSD_ST_UOM_CONVERSIONS 0 rows exported
. . exporting table MSD_TIME 2192 rows exported
. . exporting table MSD_UOM_CONVERSIONS 0 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting referential integrity constraints
. exporting triggers
. exporting posttables actions
. exporting snapshots
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
Export terminated successfully without warnings.
The question is for the tables that were exported that did not contain any data the log states that 0 rows were exported. Did the table definition get exported? If there is a better forum to post this message please let me know and I apologize.
Sincerely,
Dan H.
nullHi,
The answer is Yes.
You have made a User type export.
So all the objects (definitions and data where available) are exported from the schema you specified.
Cristian.
null -
hi gurus
i am placing some questions. i know that this is not right to place some 30 questions, but please take some time to answer so that we can benifit.
thanks
regards
sridhar
[email protected]
1. What is table partition?
2. What are the options available in transfer rule and when ABAP code is recquired during the transfer rule what important variables you can use?
3. How would you optimize the dimensions?
4. What are the conversion routines for units and currencies in the update rule?
5. Can you make an infoobject as info provider and why?
6. What are the steps to unload non cumulative cubes?
7. Give step to step approach to archiving cubex.
8. What are the load process and post processing.
9. What are the data target administration task
10. What are the parallel process that could have locking problems
11. How would you convert a info package group into a process chain?
12. How do you transoform Open Hub Data?
13. What are the data loading tuning one can do?
14. What is ODS?
15. What is the use of BW Statistics?
16. What are the options when definging aggregates?
17. How will you debug errors with SAP GUI (like Active X error etc)
18. When you write user exit for variables what does I_Step do?
19. How do you replace a query result from a master query to a child query?
20. How do you define exception reporting in the background?
21. What kind of tools are available to monitor the overall Query Performance?
22. What can I do if the database proportion is high for all queries?
23. How to call a BW Query from an ABAP program?
24. What are the extractor types?
25. What are the steps to extract data from R/3?
26. What are the steps to configure third party (BAPI) tools?
27. What are the delta options available when you load from flat file?
28. What are the table filled when you select ABAP?
29. What are the steps to create classes in SAP-BW
30. How do you convert from LIS to LO extraction?
31. How do you keep your self-updated on major SAP Develppments, Give an analytical example.hi sridhar,
if u use this link, u can get morethan 75% answers...
http://www.sap-basis-abap.com/bw/sap-bw-interview-questions.htm
with hopes
Raja Singh -
hi all
select regexp_count('1|2|3|4|'5,'|')from dual
how to count the no of pipe symbols in the string , it gives value10,please help meHi,
Isn't this the same question as
https://community.oracle.com/message/11318287
and
https://community.oracle.com/thread/2617312
Please don't post the same question over and over. Mark this thread as "Answered" right away, and continue in the thread above, if necessary. -
Reg Exp and non capturing groups
Hello,
I got problems with the non capturing groups in java.
I want to extract the 2nd ocurenc of a given patern from a string.
This ist the string =" 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text"
Now I want to extract the 2nd occurecy of the brackets with an unknow text pattern.
I tried this pattern = "(?:\[\w+\] )\[w+\]"
I thought that the non-capturing pattern helps me to find the first pair of [] brackets. the capturing group should give me want i want.
But I still get the result: [Logging] [Success]"
Even if I try just to use only the non cpaturing patern "(?:\[\w+\])" I still get an output from Matcher.group() which I didnt expect here!
What I am doing wrong?
Thanx for any helpSorry, sabre150 I just missed it to answer you.
I have placed it into eclipse in a scrapbookpage into the following code:
final String regexp = "[^\\]]*\\[[^\\]]*\\]\\s*(.*)";
final String zeile = " 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text";
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexp);
java.util.regex.Matcher matcher = pattern.matcher("");
matcher.reset(zeile);
System.out.println("Found: "+matcher.find());
System.out.println(matcher.group());Output was:
Found: true
12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text
and not what I wanted
"[Success] ### More text [Perhaps ...."
I dont know what I am doing wrong.
I thought I could solve it with the non-capturing group, but they doesnt seem to work.
My question to the non-capturing group is:
I have this pattern [code]"(?:.*)".
This pattern will probably match the String "Hello Mary!"
But it should not capture the string.
So matcher.find() is true, but matcher.group() is the whole string and nit null, like I expected. -
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]); -
Regular exp. question...
Hi,
I wrote a basic function which implements a saving of two text data into user selected files. The user chooses one file name and the program should have appended a _CH_B string to the user selected name and saved the second file with that new generated name. For some reason my regular expression part does not work even though i checked the reg. exression on a stand alone engine. Please see my attached program
Message Edited by RSibagatullin on 07-30-2008 07:02 PM
Attachments:
TextSave2.vi 56 KB
current_path_20070710.vi 13 KBI prefer less code.
Maybe try something like in the attached. Modify as needed.
(Seems oyu want to append, so add a few things inside the small FOR loop. )
Message Edited by altenbach on 07-30-2008 08:49 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
TextSave2MOD.vi 18 KB
Maybe you are looking for
-
How do I turn off apps running in the background on iOS7?
I just updated my iPhone 5 to iOS7. How do I turn off apps running in the background? Double tapping the home button and turning each one off doesn't work on the updated iOS.
-
Hi Experts I need to keep the users of my AS Java syncronized with some user in ERP. Thats means, when some user change some information in ABAP, i need to get this information and change in AS Java too, like email or password... I can't use CUA, and
-
I am having problems with my time capsule and WiFi. I had previously set it up and everything was a-ok. Recently we had to move out of the house while there waswork being done on the floors. My guess is everything was unplugged and re-plugged. Now th
-
HT204074 How do I remove a device from my itunes account?
I am trying to remove my daughter's ipod from my account as she broke it and we are replacing it with a new one. I no longer want it listed as one of my devices. However, there is NO "Manage Devices" option anywhere on my screen!!! I have looked e
-
JTable -showing column headers and displaying multi-line strings
Hi, This is two questions really. #1 - Does anyone know why my column headers aren't showing in my jtable using the model below? #2 - Does anyone know how I can display, mulitple line strings in a jtable? Currently my newline character ('\n') is just