Requirement to update a column by using Regular Expression
Hi All,
I have a requirement to update a column which is having values like below code.
based on the conditinos I need to update from ‘E’ to ‘Z’. Few positions I need to update and remaining positions I need leave as it is.
How I can achive this requirement by using regular expression regexp_replace.
Actual value --> 'AEAAAEAA EE AA EE AA EE EEEAA AA AA '
After update --> 'AZAAAZAA EE AA EE AA EE EEEAA AA AA '
below is my requirement. I am adding the conditions dynamically as per the conditions. I dont know the position of the E. If 'E' is in any position I need to update with 'Z' if that 'E' satisfy the condition.
I dont want to update all the E's to Z's.
I want to update specific E's which satisfy the condition.
IF l_kwhhilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,1,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\1';
END IF;
IF l_kwhilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,2,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\2';
END IF;
IF l_kvahilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,3,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\3';
END IF;
IF l_kvarhilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,4,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\4';
END IF;
IF l_todkwh1hilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,5,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\5';
END IF;
IF l_todkwh2hilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,6,1) = ''E'' OR ';
l_exp := l_exp||'Z';
ELSE
l_exp := l_exp||'\6';
END IF;
l_exp := ''''||l_exp||'''';
l_exp1 := '\1\2\3\4'||l_exp1;
IF l_todkw1hilow >= 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,11,1) = ''E'' OR ';
l_exp1 := l_exp1||'Z';
ELSE
l_exp1 := l_exp1||'\5';
END IF;
IF l_todkw2hilow = 1 THEN
l_where := l_where||' SUBSTR(OVERRIDEFIELD,12,1) = ''E'' OR ';
l_exp1 := l_exp1||'Z';
ELSE
l_exp1 := l_exp1||'\6';
END IF;
l_exp1 := ''''||l_exp1||'''';
IF i give 10 in the regexp_replace it is not working.
SET OVERRIDEFIELD = REGEXP_REPLACE(SUBSTR(overridefield,1,6), ''(.)(.)(.)(.)(.)(.)'','||l_exp||')'||
' ||REGEXP_REPLACE(SUBSTR(overridefield,7,6), ''(.)(.)(.)(.)(.)(.)'','||l_exp1||')'||
' ||SUBSTR(overridefield,13)'||
Similar Messages
-
How to auto update date column without using trigger
Hi,
How to write below MYSQL query in Oracle 10g :
CREATE TABLE example_timestamp (
Id number(10) NOT NULL PRIMARY KEY,
Data VARCHAR(100),
Date_time TIMESTAMP DEFAULT current_timestamp on update current_timestamp
I need to auto update the Date_Time column without using trigger when ever i update a record.
Example shown below is from MYSQL. I want to perform the below steps in ORACLE to auto update Date_Time column.
mysql> INSERT INTO example_timestamp (data)
VALUES ('The time of creation is:');
mysql> SELECT * FROM example_timestamp;
| id | data | Date_Time |
| 1 | The time of creation is: | 2012-06-28 12:37:22 |
mysql> UPDATE example_timestamp
SET data='The current timestamp is: '
WHERE id=1;
mysql> SELECT * FROM example_timestamp;
| id | data | Date_Time |
| 1 | The current timestamp is: | 2012-06-28 12:38:55 |
Regards,
Yogesh.Is there no functionality in oracle to auto update date column without using trigger??
I dont want to update the date column in UPDATE statement.
The date column should automatically get updated when ever i execute an Update statement. -
Pattern matching using Regular expression
Hi,
I am working on pattern matching using regular expression. I the table, I have 2 columns A and B
A has value 'A499BPAU4A32A386KBCZ4C13C41D20E'
B has value like '*CZ4*M11*7NQ+RDR+RSM-R9A-R9B'
the requirement is that I have to match the columns of B in A. If there is a value with * sign, this must be present in A like 'CZ4' should exit in string A.
The issue I am facing is that there are 2 values with * sign. The code works fine for first match (CZ4) but it does not look further as M11 does not exist in A.
I used the condition
AND instr(A,substr(REGEXP_SUBSTR(B, '*[^*]{3}'),2) ,1)=0
First of all, is this possible to match multiple patterns in one condition?
If yes, please suggest.
Thanksuser2544469 wrote:
Thanks a lot Frank. This query worked wonderful for the test data I have provided however I have some concerns:
- query doesnot include the column BOOK which is a mandatory check.Sorry, that was my mistake. It was a very easy mistake to make, since you posted sample data where it didn't matter. Instead of doing a cross-join between vn and got_must_have_cnt, do an inner join, using book. That means book will have to be in got_must_have_cnt, and all the sub-queries from which it descends. Look for comments that say "March 22".
If you want to treat '+' in test_cat.codes as '*', then the simplest thing is probably just to use REPLACE, so that when the table has '+', you use '*' instead.
WITH got_token_cnt AS
SELECT cat
, book -- Added March 22
, REPLACE (codes, '+', '*') AS codes -- If desired. Changed March 22
, LENGTH (codes) - LENGTH ( TRANSLATE ( codes
, 'x*+-'
, 'x'
) AS token_cnt
FROM test_cat
, cntr AS
SELECT LEVEL AS n
FROM ( SELECT MAX (token_cnt) AS max_token_cnt
FROM got_token_cnt
CONNECT BY LEVEL <= max_token_cnt
, got_tokens AS
SELECT t.cat
, t.book -- Added March 22
, REGEXP_SUBSTR ( t.codes
, '[*+-]'
, 1
, c.n
) AS token_type
, SUBSTR ( REGEXP_SUBSTR ( t.codes
, '[*+-][^*+-]*'
, 1
, c.n
, 2
) AS token
FROM got_token_cnt t
JOIN cntr c ON c.n <= t.token_cnt
, got_must_have_cnt AS
SELECT cat, book -- Changed March 22
, COUNT (CASE WHEN token_type = '*' THEN 1 END) AS must_have_cnt
FROM got_tokens
GROUP BY cat, book -- Changed March 22
SELECT mh.cat
, vn.vn_no
FROM got_must_have_cnt mh
JOIN vn ON mh.book = vn.book -- Changed March 22
LEFT OUTER JOIN got_tokens gt ON mh.cat = gt.cat
AND INSTR (vn.codes, gt.token) > 1
GROUP BY mh.cat
, mh.must_have_cnt
, vn.vn_no
HAVING COUNT (CASE WHEN gt.token_type = '*' THEN 1 END) = mh.must_have_cnt
AND COUNT (CASE WHEN gt.token_type = '-' THEN 1 END) = 0
ORDER BY mh.cat
- query is very slow with 60000 records in vn table. Cost is somewhere around 36000.See these threads:
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting
Relational databases were designed to have (at most) one piece of information in each column. If you decide to have multiple items in the same column (as you have a variable number of tokens in the codes column), don't be surprised if that makes things slower and more complicated. Most of the query I posted, and perhaps most of the time needed, is jsut to normalize the data. If you stored the data in a narmalized form, perhaps something like got_tokens, then you wouldn't need the first 3 sub-queries that I posted.
Edited by: Frank Kulash on Mar 22, 2011 12:04 PM -
ADF Email Validation using Regular Expression
Hi,
Wanted to add Email Validation VO search.
It is working if i put
<af:validateRegExp pattern="[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}"
messageDetailNoMatch="The value {1} is not a valid email address:"/>However this requires email id to be entered in Capital Letters.
Tried with below option is not working.
<af:inputText value="#{bindings.xxEmail.inputValue}" label="Email"
required="#{bindings.xxEmail.hints.mandatory}"
columns="#{bindings.xxEmail.hints.displayWidth}"
maximumLength="#{bindings.xxEmail.hints.precision}"
shortDesc="#{bindings.xxEmail.hints.tooltip}" id="it5">
<f:validator binding="#{bindings.xxEmail.validator}"/>
<f:validateLength minimum="6"/>
<af:validateRegExp pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"
messageDetailNoMatch="The value {1} is not a valid email address:"/>
</af:inputText>I got above info from
ADF Email Validation using Regular Expression
User don't enter email id Without @ .
Kindly suggest pattern to achive this.
Thanks,
jit
Edited by: appsjit on Jan 25, 2013 7:08 PMThe RegEx to check EMail after RFC2822
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?There are still some missing parts in the check as not all suffix combinations are allowed, but this is pretty good.
Timo -
Request some help, over procedure's performance uses regular expressions for its functinality
Hi All,
Below is the procedure, having functionalities of populating two tables. For first table, its a simple insertion process but for second table, we need to break the soruce record as per business requirement and then insert into the table. [Have used regular expressions for that]
Procedure works fine but it takes around 23 mins for processing 1mm of rows.
Since this procedure would be used, parallely by different ETL processes, so append hint is not recommended.
Is there any ways to improve its performance, or any suggestion if my approach is not optimized? Thanks for all help in advance.
CREATE OR REPLACE PROCEDURE SONARDBO.PRC_PROCESS_EXCEPTIONS_LOGS_TT
P_PROCESS_ID IN NUMBER,
P_FEED_ID IN NUMBER,
P_TABLE_NAME IN VARCHAR2,
P_FEED_RECORD IN VARCHAR2,
P_EXCEPTION_RECORD IN VARCHAR2
IS
PRAGMA AUTONOMOUS_TRANSACTION;
V_EXCEPTION_LOG_ID EXCEPTION_LOG.EXCEPTION_LOG_ID%TYPE;
BEGIN
V_EXCEPTION_LOG_ID :=EXCEPTION_LOG_SEQ.NEXTVAL;
INSERT INTO SONARDBO.EXCEPTION_LOG
EXCEPTION_LOG_ID, PROCESS_DATE, PROCESS_ID,EXCEPTION_CODE,FEED_ID,SP_NAME
,ATTRIBUTE_NAME,TABLE_NAME,EXCEPTION_RECORD
,DATA_STRUCTURE
,CREATED_BY,CREATED_TS
VALUES
( V_EXCEPTION_LOG_ID
,TRUNC(SYSDATE)
,P_PROCESS_ID
,'N/A'
,P_FEED_ID
,NULL
,NULL
,P_TABLE_NAME
,P_FEED_RECORD
,NULL
,USER
,SYSDATE
INSERT INTO EXCEPTION_ATTR_LOG
EXCEPTION_ATTR_ID,EXCEPTION_LOG_ID,EXCEPTION_CODE,ATTRIBUTE_NAME,SP_NAME,TABLE_NAME,CREATED_BY,CREATED_TS,ATTRIBUTE_VALUE
SELECT
EXCEPTION_ATTR_LOG_SEQ.NEXTVAL EXCEPTION_ATTR_ID
,V_EXCEPTION_LOG_ID EXCEPTION_LOG_ID
,REGEXP_SUBSTR(str,'[^|]*',1,1) EXCEPTION_CODE
,REGEXP_SUBSTR(str,'[^|]+',1,2) ATTRIBUTE_NAME
,'N/A' SP_NAME
,p_table_name
,USER
,SYSDATE
,REGEXP_SUBSTR(str,'[^|]+',1,3) ATTRIBUTE_VALUE
FROM
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
WHERE REGEXP_SUBSTR(str,'[^|]*',1,1) IS NOT NULL
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
Many Thanks,
ArpitRegex's are known to be CPU intensive specially when dealing with large number of rows.
If you have to reduce the processing time, you need to tune the Select statements.
One suggested change could be to change the following query
SELECT
REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,t2.COLUMN_VALUE) str
FROM
DUAL t1 CROSS JOIN
TABLE
CAST
MULTISET
SELECT LEVEL
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
AS SYS.odciNumberList
) t2
to
SELECT REGEXP_SUBSTR(P_EXCEPTION_RECORD, '([^^])+', 1,level) str
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT(P_EXCEPTION_RECORD, '([^^])+')
Before looking for any performance benefit, you need to ensure that this does not change your output.
How many substrings are you expecting in the P_EXCEPTION_RECORD? If less than 5, it will be better to opt for SUBSTR and INSTR combination as it might work well with the number of records you are working with. Only trouble is, you will have to write different SUBSTR and INSTR statements for each column to be fetched.
How are you calling this procedure? Is it not possible to work with Collections? Delimited strings are not a very good option as it requires splitting of the data every time you need to refer to. -
Trying to use regular expressions to convert names to Title Case
I'm trying to change names to their proper case for most common names in North America (esp. the U.S.).
Some examples are in the comments of the included code below.
My problem is that *retName = retName.replaceAll("( [^ ])([^ ]+)", "$1".toUpperCase() + "$2");* does not work as I expect. It seems that the toUpperCase method call does not actually do anything to the identified group.
Everything else works as I expect.
I'm hoping that I do not have to iterate through each character of the string, upshifting the characters that follow spaces.
Any help from you RegEx experts will be appreciated.
{code}
* Converts names in some random case into proper Name Case. This method does not have the
* extra processing that would be necessary to convert street addresses.
* This method does not add or remove punctuation.
* Examples:
* DAN MARINO --> Dan Marino
* old macdonald --> Old Macdonald <-- Can't capitalize the 'D" because of Ernst Mach
* ROY BLOUNT, JR. --> Roy Blount, Jr.
* CAROL mosely-BrAuN --> Carol Mosely-Braun
* Tom Jones --> Tom Jones
* ST.LOUIS --> St. Louis
* ST.LOUIS, MO --> St. Louis, Mo <-- Avoid City Names plus State Codes
* This is a work in progress that will need to be updated as new exceptions are found.
public static String toNameCase(String name) {
* Basic plan:
* 1. Strategically create double spaces in front of characters to be capitalized
* 2. Capitalize characters with preceding spaces
* 3. Remove double spaces.
// Make the string all lower case
String retName = name.trim().toLowerCase();
// Collapse strings of spaces to single spaces
retName = retName.replaceAll("[ ]+", " ");
// "mc" names
retName = retName.replaceAll("( mc)", " $1");
// Ensure there is one space after periods and commas
retName = retName.replaceAll("(\\.|,)([^ ])", "$1 $2");
// Add 2 spaces after periods, commas, hyphens and apostrophes
retName = retName.replaceAll("(\\.|,|-|')", "$1 ");
// Add a double space to the front of the string
retName = " " + retName;
// Upshift each character that is preceded by a space
// For some reason this doesn't work
retName = retName.replaceAll("( [^ ])([^ ]+)", "$1".toUpperCase() + "$2");
// Remove double spaces
retName = retName.replaceAll(" ", "");
return retName;
Edited by: FuzzyBunnyFeet on Jan 17, 2011 10:56 AM
Edited by: FuzzyBunnyFeet on Jan 17, 2011 10:57 AMHopefully someone will still be able to provide a RegEx solution, but until that time here is a working method.
Also, if people have suggestions of other rules for letter capitalization in names, I am interested in those too.
* Converts names in some random case into proper Name Case. This method does not have the
* extra processing that would be necessary to convert street addresses.
* This method does not add or remove punctuation.
* Examples:
* CAROL mosely-BrAuN --> Carol Mosely-Braun
* carol o'connor --> Carol O'Connor
* DAN MARINO --> Dan Marino
* eD mCmAHON --> Ed McMahon
* joe amcode --> Joe Amcode <-- Embedded "mc"
* mr.t --> Mr. T <-- Inserted space
* OLD MACDONALD --> Old Macdonald <-- Can't capitalize the 'D" because of Ernst Mach
* old mac donald --> Old Mac Donald
* ROY BLOUNT,JR. --> Roy Blount, Jr.
* ST.LOUIS --> St. Louis
* ST.LOUIS,MO --> St. Louis, Mo <-- Avoid City Names plus State Codes
* Tom Jones --> Tom Jones
* This is a work in progress that will need to be updated as new exceptions are found.
public static String toNameCase(String name) {
* Basic plan:
* 1. Strategically create double spaces in front of characters to be capitalized
* 2. Capitalize characters with preceding spaces
* 3. Remove double spaces.
// Make the string all lower case
String workStr = name.trim().toLowerCase();
// Collapse strings of spaces to single spaces
workStr = workStr.replaceAll("[ ]+", " ");
// "mc" names
workStr = workStr.replaceAll("( mc)", " $1 ");
// Ensure there is one space after periods and commas
workStr = workStr.replaceAll("(\\.|,)([^ ])", "$1 $2");
// Add 2 spaces after periods, commas, hyphens and apostrophes
workStr = workStr.replaceAll("(\\.|,|-|')", "$1 ");
// Add a double space to the front of the string
workStr = " " + workStr;
// Upshift each character that is preceded by a space and remove double spaces
// Can't upshift using regular expressions and String methods
// workStr = workStr.replaceAll("( [^ ])([^ ]+)", "$1"toUpperCase() + "$2");
StringBuilder titleCase = new StringBuilder();
for (int i = 0; i < workStr.length(); i++) {
if (workStr.charAt(i) == ' ') {
if (workStr.charAt(i+1) == ' ') {
i += 2;
while (i < workStr.length() && workStr.charAt(i) == ' ') {
titleCase.append(workStr.charAt(i++));
if (i < workStr.length()) {
titleCase.append(workStr.substring(i, i+1).toUpperCase());
} else {
titleCase.append(workStr.charAt(i));
return titleCase.toString();
{code} -
Changeparticular characters in a string by using regular expressions ...
Hello Everyone,
I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
Is it possible by using regular expressions in oracle ?
Can you give me some clues ?
Thank youSSU wrote:
Hello Everyone,
I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
Is it possible by using regular expressions in oracle ?
Can you give me some clues ?
Thank you
SQL> SELECT
2 regexp_replace('sdfsdf Sdfdfs Sdfd','s|S','X') from dual;
REGEXP_REPLACE('SD
XdfXdf XdfdfX XdfdRegards,
Achyut -
Using regular expressions for validation in i18n
Can we use regular expressions for validation of inputs in a java application taking care of i18N aspects too. Zip code for different locales are different. Can we use regular expressions to validate zipcode inputs from different locales
hi,
For that shall i have to create individual patterns for matching the inputs from different locales or a single pattern will do in the case of validating phone nos. around the world, zip codes etc. In case different patterns are required, programmer should have a konwledge of difference in patters for different locales.
regards
sdas -
Using regular expressions to get a customized output
Hi,
I have a string/varchar variable with the data ',a,b,c,' in it.
I want the display as follows:
a
b
c
I would like to get the similar output using regular expressions.
How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
Please do the needful.
Thanks & Regards,
RakshitI remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
-- end of sample data
SELECT col_new
FROM t
MODEL
PARTITION BY (ROWNUM rn)
DIMENSION BY (0 dim)
MEASURES(col1, col1 col_new)
RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
(col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
COL_NEW
aaaa
bbbb
cccc
dddd
eeee
ffff
7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
-- end of sample data
SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
FROM t
CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
;C. -
I do have a table with one varchar2 column with the following values:
COL_NAME
1.1.3.TECH.SG.1.Action.2
1.1.3.TECH.SG.1.Action.3
1.1.3.TECH.SG.1.Action.4
1.1.3.TECH.SG.1.Action.5
1.1.3.TECH.SG.1.Action.6
I need the last digit to be reduced by 1 like below:
COL_NAME NEW_VALUE
1.1.3.TECH.SG.1.Action.2 1.1.3.TECH.SG.1.Action.1
1.1.3.TECH.SG.1.Action.3 1.1.3.TECH.SG.1.Action.2
1.1.3.TECH.SG.1.Action.4 1.1.3.TECH.SG.1.Action.3
1.1.3.TECH.SG.1.Action.5 1.1.3.TECH.SG.1.Action.4
1.1.3.TECH.SG.1.Action.6 1.1.3.TECH.SG.1.Action.5
How can this be achieved by a SQL statement using Regular Expression ?
Pls suggest.
Regards
MSYou don't really need regexps, you can just use normal instr() and substr():
1 with v as (
2 select '1.1.3.TECH.SG.1.Action.2' as val from dual union all
3 select '1.1.3.TECH.SG.1.Action.3' as val from dual union all
4 select '1.1.3.TECH.SG.1.Action.4' as val from dual union all
5 select '1.1.3.TECH.SG.1.Action.5' as val from dual union all
6 select '1.1.3.TECH.SG.1.Action.6' as val from dual
7 )
8 select val
9 , substr(val, 1, instr(val, '.', -1))
10 || to_char(to_number(substr(val, instr(val, '.', -1) + 1)) + 1) new_val
11* from v
SQL> /
VAL NEW_VAL
1.1.3.TECH.SG.1.Action.2 1.1.3.TECH.SG.1.Action.3
1.1.3.TECH.SG.1.Action.3 1.1.3.TECH.SG.1.Action.4
1.1.3.TECH.SG.1.Action.4 1.1.3.TECH.SG.1.Action.5
1.1.3.TECH.SG.1.Action.5 1.1.3.TECH.SG.1.Action.6
1.1.3.TECH.SG.1.Action.6 1.1.3.TECH.SG.1.Action.7
5 rows selected.cheers,
Anthony -
Finding URLs using regular expression.
I have an requirement where user will type some text containing URLs like "Please visit this site http://www.google.com/e/qHvQcWco`~!@#$%^&*()-7747. Thank you". This text has to be modified as below before saving it to the database.
"Please visit this site <a href='http://www.google.com/e/qHvQcWco`~!@#$%^&*()-7747'>http://www.google.com/e/qHvQcWco`~!@#$%^&*()-7747</a>. Thank you"
I am using regular expression (http|https)://.+?\\s which marks the end of the url with a white space character.This pattern doesn't work if the URL is located at the end of the string since there will be no space at the end.
For example if the string is "Please visit this site http://www.google.com/e/qHvQcWco`~!@#$%^&*()-7747" the regex will fail.
My acutal problem is to find the URL irrespective its position within the string.
Pattern urlPattern = Pattern.compile("(http|https)://.+?\\s", Pattern.CASE_INSENSITIVE);
Matcher matcher = urlPattern.matcher(plainText);
Map stringIndexMap = new HashMap();
//Searching the input string for urlPattern...
while(matcher.find()) {
String urlString = matcher.group();
//Storing the urls in a hashmap with their indices as keys....
stringIndexMap.put(new Integer(matcher.start()), urlString.trim());
Set keySet = stringIndexMap.keySet();
Iterator it = keySet.iterator();
//Iterating over the hashmap containing urls...
while(it.hasNext()) {
String urlString = (String) stringIndexMap.get(it.next());
* Replacing the url string in the input text with <a href="#" onclick="window.open('<urlString>')"
* using String index
clickableURLString.replace(clickableURLString.indexOf(urlString),
clickableURLString.indexOf(urlString) + urlString.length(),
"<a href=\"#\" onclick=\"window.open('" + urlString
+ "')\">" + urlString + "</a>");
return clickableURLString.toString();The end of the input is '$' as a regex.
import java.util.regex.*;
public class Prasanna{
public static void main(String[] args){
String text
= "Please visit this site http://www.google.com/e/qHvQcWco`~!@#$%^&*()-7747";
// String regex = "(http|https)://.+?(?:\\s|$)"; // this works
String regex = "(http|https)://[^ ]+"; // this also works
Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher mat = pat.matcher(text);
while (mat.find()){
System.out.println(mat.group());
} -
Date Validation (yyyy/MM/dd) Using Regular Expression
Hi Friends,
I want to validate date entered by user in yyyy/MM/dd format and for this I want to use Regular Expressions only. Also is there any tool that can be used to generate Regular Expression (for Win2000, Win NT)?
Regards,
Himanshu Rathoretry this
public class Test
public static void main(String [] args)
String regex = "\\d{4}/[01]\\d/[0-3]\\d";
System.out.println("2003/12/11".matches(regex));
System.out.println("2djd/kj3".matches(regex));
System.out.println("22/12/12".matches(regex));
System.out.println("2003/23/05".matches(regex));
System.out.println("1999/12/51".matches(regex));
System.out.println("2007/05/07".matches(regex));
}i'm not able to try on it because i only have jdk1.3.1 installed on my computer and these codes
required j2sdk1.4 -
Validate cfinput using regular expression
Hi,
can somebody help me valditing an cfinput field using regular expressions?
First digit must be a number or "R".
Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.
I try this, but it doesn't work (Sorry I'm a beginner using regex).
<cfinput type="text" name="field1" required="yes" validate="regular_expression" pattern="[0-9Rr][0-9a-zA-Z]*" maxlength="15">
Thank you in advice!
ClaudiaYou haven't told your regex to match the entire string, so it will "pass"
any string that has your match anywhere within it, so like as long as it's
got an R or a digit in it: it's OK.
To tell it to match the entire string, anchor it to the start and end of the
string with ^ and $ respectively.
Regular expression syntax: Using special characters
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38f -7ffb.html#WSc3ff6d0ea77859461172e0811cbec0a38f-7fef
Adam -
Format string using Regular Expression
Input string output format...
SELECT q'<select ab_c "ABC", efg "EFG" from dual>' str FROM DUAL
Output:
STR
select ab_c "ABC", efg "EFG" from dual
Required output format using regular expression...
STR
select 'ab_c' "ABC", 'efg' "EFG" from dualRegular expressions have many limitations as parsing tools, and you didn't specify the rules you wanted. This expression puts quotes around the non blank string before a quoted string:
SELECT regexp_replace(q'<select ab_c "ABC", efg "EFG" from dual>',
'([^" ]+)( +"[^ ]*")' , '''\1''\2' ) str FROM DUAL;
STR
select 'ab_c' "ABC", 'efg' "EFG" from dual
{code}
It is not robust - a missing " will confuse it, and you should be using bind variables anyway. -
Data generation using regular expression in c# for sql server
Hello Everybody,
I am using VS 2013 professional, SQL Server 2012.
I am writing database application in c#. I have a table which stores starttime and endtime of operator
As starting step, I inserted random DateTime into the table.
But i would like hide some Patterns inside the database like it should insert some records that operator2 is absent on every second tuesday in every month in 2014 between 3AM to 4AM.
How do i tell my c# code to insert that Patterns into databse. From some posts I understtod that it may be done by using regular expressions. But i did not find clear example.
Could someone please tell me how to do it?
Thank you so much.I'm not sure what exactly you're referring to, but I think you may be able to accomplish some of what you want by using triggers, constraints, and column defaults. These are database objects that are defined by using DDL, so have a look at the DDL reference
(and other information about these objects) in SQL Server Books Online and see if these will do what you want. T-SQL implements a "pattern-wildcard language" that is not the same as regular expressions.
In addition you can write SQLCLR objects (e.g. triggers and functions) that can use the .NET regular expression library, which is an implementation of the well-known regular expression library. There are a number of examples of SQLCLR/regular expressions
around, a simple web search should suffice.
Hope this helps, Bob
Maybe you are looking for
-
Black Ink is not working - 3525 model
My black ink wont take on the paper, I have checked all my ink levels, they are all full. I have done several printhead cleanings, and I put the nozzle in hot water for 5 minutes, it is still not working. The other three colours take on the paper, it
-
Time machine disk grayed out in Disk Utility - back up not working
The disk does not show in Time Machine. In Disk Utility it shows but is grayed out. Tried to repair disk. Got message that disk cannot be repaired. Tells me to back up and erase the disk. Not sure how to back it up if it is not being recognized
-
Transfer very large file Mac to Mac
Hi, I created an iMovie (about 17GB in size) on my ibook G4. Now I want to transfer it to my Mac Mini where I am storing media files. Thus far, my iPod has been large enough for the job, but it is a 15GB version and won't do it. I have heard firewire
-
Converting Word DOC to PDF changes to PP
I'm converting a Word DOC to PDF, and my header has several Registered marks. In Word it looks fine, but the PDF has added the letter 'P' before and after, changing '®' to 'P®P' I've tried the same source doc on two different machines, and tried usin
-
Active Directory Management Gateway Service installation error
Hey, When I attempt to install the 32 bit Server 2008 package from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=2852 I get an error saying that it's not the correct version. Just in case I tried the 3 other versions, but as