Advanced String Manipulation Using REGEXP
Hello all,
I've been trying to split a string using either REGEXP_SUBSTR and REGEXP_REPLACE functions with much success so I wonder whether anyone here can give me a hand. Basically the string I want to split in to 3 is in this format:
'instanceno;partno;serialno'
I have read numerous articles within last few days but I still can't get it to working (I'm sure due to my lack of regular expression handling knowledge in OBIEE). I found two articles discussing similar scenarios. One in here and the other one is here. Both of those are good, but I cannot apply those principles to my query as I'm keep getting issues with the use of semicolon (;).
Could someone explain to me how to split this string so I can have 3 separate columns, please?
Thanks and regards,
Hi Anuhas,
you have to create 3 columns in the report on 3 attribute columns inside le Logical Model with this syntax for the the string str = 'instanceno;partno;serialno'
COLUMN1 = evaluate('regexp_substr(%1,''[^\;]+'', 1,1)',REPLACE(*str*,';','\;'))
COLUMN2 = evaluate('regexp_substr(%1,''[^\;]+'', 1,2)',REPLACE(*str*,';','\;'))
COLUMN3 = evaluate('regexp_substr(%1,''[^\;]+'', 1,3)',REPLACE(*str*,';','\;'))
You have to use the REPLACE function (; --> \;) because the ; is e special character
In this way you have:
COLUMN1 = instanceno
COLUMN2 = partno
COLUMN3 = serialno
The regex_substr(a,b,c) contains:
a = str the string
b = [^\;]+ find for the beginning of the string the character ;
c = number of occurrence
I hope it hepls.
Regards,
Gianluca
Similar Messages
-
Hi ,
I am new to this:
I have the following requirement :
String1: '1,12,4'
String2: '2'
[both strings could be comma separated]
I need to check if evey member of String2 exists in String1. I was able to write the PL/SQL code for looping but when i use : select REGEXP_SUBSTR ('1,12,4','2') from dual, I get 2 as the result which is incorrect. Can someone please help me with this ?
Thanks in advanceHi,
Ssharma21 wrote:
Will there always be exactly 1 string1 and 1 string2, or will you be getting.multiple values (from a table, for example)?
Ans
Both Strings have comma separated values.
Ex: String1 ='1,2,3'
String ='2,3'
Are both strings ordered the same way? That is, given that '12' comes before '4' in string1, can we be sure that '12' will come before '4' when both appear in string2 ?
Ans
What if there are duplicates in either string?
Ans: No duplicates
I wrote the following piece of code :
BEGIN
v_levelIncludedFlag := FALSE;
v_tempFlag := TRUE;
v_array := APEX_UTIL.string_to_table (v_String2, ',');
FOR i IN 1 .. v_array.COUNT
LOOP
IF REGEXP_SUBSTR (v_String1, v_array (i)) IS NOT NULL
THEN
v_levelIncludedFlag := TRUE;
ELSE
v_levelIncludedFlag := FALSE;
END IF;
v_levelIncludedFlag := v_levelIncludedFlag AND v_tempFlag;
v_tempFlag := v_levelIncludedFlag;
END LOOP;
END
Just the REGEXP_SUBSTR is not giving me the correct result due when String1='12' and String2='2' . I should be getting NULL from REGEXP_SUBSTR (v_String1, v_array (i))
The 1
st question is: Will you be comparing exactly 1 comma-delimited string against exactly 1 comma-delimited string?
It looks like you forgot to post the answer to the 2nd question.
Depending on your answers, you might want something like this:
VARIABLE string1 VARCHAR2 (100)
VARIABLE string2 VARCHAR2 (100)
EXEC :string1 := '1,12,4';
EXEC :string2 := '12,1';
WITH s1 AS
SELECT REGEXP_SUBSTR ( :string1
, '[^,]+'
, 1
, LEVEL
) AS item
FROM dual
CONNECT BY LEVEL <= REGEXP_COUNT (:string1, '[^,]+')
, s2 AS
SELECT REGEXP_SUBSTR ( :string2
, '[^,]+'
, 1
, LEVEL
) AS item
FROM dual
CONNECT BY LEVEL <= REGEXP_COUNT (:string1, '[^,]+')
SELECT CASE
WHEN COUNT (s2.item) = 0
THEN 'Everything in ' || :string2 || ' is also in ' || :string1
ELSE 'Something in ' || :string2 || ' is missing from ' || :string1
END AS output
FROM s2
LEFT OUTER JOIN s1 ON s1.item = s2.item
WHERE s1.item IS NULL
Whatever your requirements are, you probably don't need PL/SQL, though you may want to use PL/SQL for several reasons. -
String manipulation function (regexp?)
Hi,
I am trying to extract several items from one string and concatenate them into another string with a separator.
Example
input: UV23_I2_P0_NUM > UV23_I2_P1_NUM AND UV23_I2_P1_NUM > UV23_I2_P2_NUM AND UV24_I4_P0_TXT = 'YES'
output: UV23_I2_P0_NUM;UV23_I2_P1_NUM;UV23_I2_P1_NUM;UV23_I2_P2_NUM;UV24_I4_P0_TXT
In short: extracting the UV bits an concatenate them into a new string...the operators and other stuff should not be in the new string.
Anybody knows of a function which does that?
Hint: the bits that I want to keep always start with UV and end with either NUM or TXT.
I already looked at the regexp function but its not really all that straight forward to me...
My database is 10g R2
Thanks!Hi,
Merijn8106997 wrote:
... I'll be checking those regexp functions more closely from now on...seeing them in action explains a lot more than just looking at manuals....Yes, the manual is a valuable reference, but it's just a reference. A dictionary is a reference; when you're learning a foreign language, it's extremely valuable to have a dictionary, but that's not the best way to learn the language. I should have thought about that earlier and posted a little bit of an explanation.
Here's one rather subtle point, concerning the '?' in the middle of the pattern, which means the expression right before it is Non-Greedy :
SELECT TRIM ( BOTH ';'
FROM REGEXP_REPLACE ( str
, '(^|NUM|TXT)(.*?)(UV|$)'
-- |
-- This ? means "non-greedy"
, '\1;\3'
) AS new_str
FROM table_x
;By default regular expressions are Greedy , that is, when there is a choice about how much a given pattern will match, it it will match as much as possile.
In the example above, \2 is the 0 or more characters that comes after either the beginning of the string, or NUM or TXT, and comes before either UV or the end of the string. Where is the first occurrence of that pattern in the example you gave:
input: UV23_I2_P0_NUM > UV23_I2_P1_NUM AND UV23_I2_P1_NUM > UV23_I2_P2_NUM AND UV24_I4_P0_TXT = 'YES'
position: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
1 2 3 4 5 6 7 8 9Where is the beginning of the 1st instance of the pattern, that is, the first beginning of string, NUM or TXT? Clearly, it's the beginning of the string, before position 1.
Where is the ending of that pattern, that is, UV or end-of-string? There are occurrences of UV at positions 1, 18, 37, 54 and 73, and an end-of-string after position 94. Which one do we consider to be the end of the pattern? The default is to be greedy, and take as much as possible, so that the first (and only) occurrence of the pattern would start before postion 1 and end after position 94. The ? mark tells REGEXP_REPLACE not to be greedy, to take as little as possiible. That means the first UV, at position 1. So the first occurrence of the pattern is not the whole string,l but only the part up through the first UV, at positions 1 and 2. -
String Manipulation using Regular Expression
Hello Guys,
I stuck in a situation wherein I want to extract specific data from a column of the table .
Below are the values for a particular column wherein I want to ignore values along with bracket which are in bracket and which are like .pdf,.doc .
Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf
AM57001A(ASRM549CDH).DOC
AM23021A Identity of sulfate (draft)
PG-1183.E.2 (0.25 mg FCT)
AS149656A (DEV AERO APPL HFA WHT PROVENTIL)
Stability report (RSR) Annex2 semi-solid form (internal information)
TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf
TR3018520A Addendum 1 (PN 3018520)
AM10311A Particle size air-jet sieving (constant sieving) (draft)
ASE00099B Addendum (PN E000099) 90 mesh
AM37101_312-99 (Z11c) Palladium by DCP.doc
PS21001A_1H-NMR.doc (PN 332-00)
AM68311A (Q-One CP 33021.02) Attachment
AM68202-1A (BioReliance no. 02.102006) Attachment
I want below output for above values for column
Trisdipalladium451CDHA
AM57001A
AM23021A Identity of sulfate
PG-1183.E.2
Thanks in advanceLike this?
SQL> with t
2 as
3 (
4 select 'Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf' str from dual
5 union all
6 select 'AM57001A(ASRM549CDH).DOC' str from dual
7 union all
8 select 'AM23021A Identity of sulfate (draft)' str from dual
9 union all
10 select 'PG-1183.E.2 (0.25 mg FCT)' str from dual
11 union all
12 select 'AS149656A (DEV AERO APPL HFA WHT PROVENTIL)' str from dual
13 union all
14 select 'Stability report (RSR) Annex2 semi-solid form (internal information)' str from dual
15 union all
16 select 'TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf' str from dual
17 union all
18 select 'TR3018520A Addendum 1 (PN 3018520)' str from dual
19 union all
20 select 'AM10311A Particle size air-jet sieving (constant sieving) (draft)' str from dual
21 union all
22 select 'ASE00099B Addendum (PN E000099) 90 mesh' str from dual
23 union all
24 select 'AM37101_312-99 (Z11c) Palladium by DCP.doc' str from dual
25 union all
26 select 'PS21001A_1H-NMR.doc (PN 332-00)' str from dual
27 union all
28 select 'AM68311A (Q-One CP 33021.02) Attachment' str from dual
29 union all
30 select 'AM68202-1A (BioReliance no. 02.102006) Attachment' str from dual
31 )
32 select str
33 , regexp_replace(str, '(\([^)]+\))|(\..{3})') str_new
34 from t;
STR STR_NEW
Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf Trisdipalladium 451CDHA
AM57001A(ASRM549CDH).DOC AM57001A
AM23021A Identity of sulfate (draft) AM23021A Identity of sulfate
PG-1183.E.2 (0.25 mg FCT) PG-1183
AS149656A (DEV AERO APPL HFA WHT PROVENTIL) AS149656A
Stability report (RSR) Annex2 semi-solid form (internal information) Stability report Annex2 semi-solid form
TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf TSE-242CDH, Lancaster synthesis
TR3018520A Addendum 1 (PN 3018520) TR3018520A Addendum 1
AM10311A Particle size air-jet sieving (constant sieving) (draft) AM10311A Particle size air-jet sieving
ASE00099B Addendum (PN E000099) 90 mesh ASE00099B Addendum 90 mesh
AM37101_312-99 (Z11c) Palladium by DCP.doc AM37101_312-99 Palladium by DCP
PS21001A_1H-NMR.doc (PN 332-00) PS21001A_1H-NMR
AM68311A (Q-One CP 33021.02) Attachment AM68311A Attachment
AM68202-1A (BioReliance no. 02.102006) Attachment AM68202-1A Attachment
14 rows selected. -
String replace All using RegExp
var myString:String="<font face='arial' size='14'>ZX</font><span class='cssid'>some Text </span><font face='arial' size='14'>USP</font>"
var fontName:String="Vardana"
var fontSize:String="11"
var regexp:RegExp = /<font.*?>/;
myString = myString.replace(regexp, "<font face='"+fontName+"' size='"+fontSize+"' >");
above scripte replacing only "<font face='arial' size='14'>ZX</font>"
i need to replace : "<font face='arial' size='14'>ZX</font><span class='cssid'>some Text </span><font face='arial' size='14'>USP</font>"var regexp:RegExp = /<font.*?>/igm;
-
How to use REGEXP for case statement
Hello everyone, I'm very new here and am struggling with a using REGEXP in a case statement, OK I am using the REGEXP to find all strings that match a specific format for a particular brand of product, for example serial numbers, and I need to be able to say something like [case when(xx.brandid) = '123' then if xx.serialnumber REGEXP_LIKE(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then 'TRUE' else 'FALSE' end "TRUE/FALSE".]
Help would be greatly appreciated with this as I feel like I'm going backwards trying to figure this out
Thanks in advance for any assistance.Like this?
case
when xx.brandid = '123' and
regexp_like(xx.serialnumber,'[A-za-z][A-za-z][A-za-z]\d{5,}[A-za-z]$') then
'TRUE'
else
'FALSE'
end -
String Manipulation in BI Publisher Report Paramater
Hi,
My Problem is that I am not able to do string manipulation on BI Publisher report Prameters.
Actually I want to Show Deptno-Dname in Menu(LOV).and when I select Certain combination like '10-Accounting',and while passing the parameter:Dept I wanted to Cut the department no(10) using string manipulation functions provided by oracle in Data Model(Query) in where clause like (where deptno=to_number(substr(:Dept,1,2)).
This query is working fine in other application like TOAD,But not giving results in BI Publisher Report.
It's also not giving any error while saving or running the report.
Please suggest any solution.even I tried the following query in data model..
select DISTINCT EMP.EMPNO as EMPNO,
EMP.ENAME as ENAME,
EMP.JOB as JOB,
DEPT.LOC as LOC
from SCOTT.DEPT DEPT,
SCOTT.EMP EMP
where emp.DEPTNO=DEPT.deptno
and DEPT.deptno=nvl(to_number(substr(:department,1,2)),DEPT.deptno)
But the Parameter which I want to pass say Department('10-Accounting'),
Still it is showing employees from all departments. -
Question about string manipulation
Hello, I am practicing with Java and trying to learn it, and have a quick question. I am trying to get the count on a string of numbers for after a decimal point. the numbers are generated as the result of a math, so I can't use index, since the location of the decimal changes based on the number imputed. I want to figure this out on my own, but have hit a wall here, i've spent the past few hours trying every string command I can think of, and haven't figured it out yet, anyone mind pointing me in the right direction for which string to use? Thanks in advance for any help you can provide!
Is this what you want?
public class Fallen{
public static void main(String[] args){
String number = "123.45678";
String frac = number.substring(number.indexOf('.') + 1);
System.out.println(frac + " length=" + frac.length());
frac = number.replaceFirst("^.+\\.", "");
System.out.println(frac + " length=" + frac.length());
} -
Validate IP Address using REGEXP
Hi All,
Sub:Validate IP Address.
My requirement is as this query.
where regexp_like(col1,'^([1-126]|[128-254]).[0-255].[0-255].[1-254]$')
....I searched for a solution using REGEXP, but no luck..
Thanks in advance.
Jeneesh
(Between, this is not a buisiness requirement.But a challenge from our collegue)
Message was edited by:
jeneeshMy mistake, I was looking the Forum only..Did you? :))
cd posted his nice trilogy about regexpr's,
and in the Introduction to regular expressions ... last part. he was talking about uncluding the IP-validating topic. -
Search given string array and replace with another string array using Regex
Hi All,
I want to search the given string array and replace with another string array using regex in java
for example,
String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
String fromValue[] = {"you", "search", "for", "any"}
String toValue[] = {"me", "dont search", "never", "trip"}
so the string "you" needs to be converted to "me" i.e you --> me. Similarly
you --> me
search --> don't search
for --> never
any --> trip
I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
One Single regular expression which matches the pattern and solve the issue.
the output should be as:
If me wish to don't search never trip etc...,
Please help me to resolve this.
Thanks In Advance,
KathirAs stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
import java.util.regex.*;
public class Test
static final List<String> oldWords =
Arrays.asList("you", "search", "for", "any");
static final List<String> newWords =
Arrays.asList("me", "dont search", "never", "trip");
public static void main(String[] args) throws Exception
String str = "If you wish to search for any of these characters, "
+ "they must be preceded by the character to be interpreted";
System.out.println(doReplace(str));
public static String doReplace(String str)
Pattern p = Pattern.compile("\\b\\w+\\b");
Matcher m = p.matcher(str);
StringBuffer sb = new StringBuffer();
while (m.find())
int pos = oldWords.indexOf(m.group());
if (pos > -1)
m.appendReplacement(sb, "");
sb.append(newWords.get(pos));
m.appendTail(sb);
return sb.toString();
} This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays). -
Hello All
I'm a just a beginner and I'm need to write a web page that is totally based on JSTL. I found out that the standard java tab lib in JSTL doesnt really support string manipulation or regular expression like in perl.
As such, I would like to know what are the different options (like adding servlets/javabeans/etc) can i add to my JSTL page so that i can perform complex string manipulation to a data entered by the user in the text box?
Some of the operations that I wish to carry out on the data are:
1. check if data contains certain characters, strings
2. joining and spliting strings
3. find length of the string
4. find the position of certain character in a string
5. check if string match certain pattern.
and many more.
Would greatly appreciate if you guys can help to provide some light.
Regards
Beginner....You might find MicroNova YUZU JSP tag library (http://sourceforge.net/projects/micronova-yuzu) useful, especially if you need to support both JSP 1.2 and 2.0. Hope this helps.
-
How to configure Oracle 10g Advanced Security to use SSL concurrently with
How to configure Oracle 10g Advanced Security to use SSL concurrently with database User names and passwords
In Oracle Advanced Security Documentation it is mentioned that i can use SSL concurrently with DB user names and passwords. But when i configure the client certificate on the client my DB connection is getting authenticated using the certificate, which out passing user id or password.
We want to connect to Oracle DB over SSL channel so that the data packets are not in clear text. Also we want the user to make a connection using user id and password.
Basically we want SSL with out authentication.
Need your expert adviceRead the documentation (I have given following links assuming you are running a 32 bit architecture)
Server installations:
http://www.oracle.com/pls/db102/to_toc?pathname=install.102%2Fb14316%2Ftoc.htm&remark=portal+%28Books%29
Client installations:
http://www.oracle.com/pls/db102/to_toc?pathname=install.102%2Fb14312%2Ftoc.htm&remark=portal+%28Books%29
You can find the required books (if not using 32 bit architecture) from
http://www.oracle.com/pls/db102/portal.portal_db?selected=3 -
Hi,
I want to pass multiple query string values using the same parameter in Query String (URL) Filter Web Part like mentioned below:
http://server/pages/Default.aspx?Title=Arup&Title=Ratan
But it always return those items whose "Title" value is "Arup". It is not returned any items whose "Title" is "Ratan".
I have followed the
http://office.microsoft.com/en-us/sharepointserver/HA102509991033.aspx#1
Please suggest me.
Thanks | Arup
THanks! Arup R(MCTS)
SucCeSS DoEs NOT MatTer.Hi DH, sorry for not being clear.
It works when I create the connection from that web part that you want to be connected with the Query String Filter Web part. So let's say you created a web part page. Then you could connect a parameterized Excel Workbook to an Excel Web Access Web Part
(or a Performance Point Dashboard etc.) and you insert it into your page and add
a Query String Filter Web Part . Then you can connect them by editing the Query String Filter Web Part but also by editing the Excel Web Access Web Part. And only when I created from the latter it worked
with multiple values for one parameter. If you have any more questions let me know. See you, Ingo -
How to read from a xml file(in String format) using a java program
hi friends
i have a string , which is xml format. i want read the values and display it.can any one suggest how to read a xml file of string format using a javaprogram
thanksfinal DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final InputStream documentStream = new ByteArrayInputStream(documentXMLSourceString.getBytes("utf-8"));
final Document document = db.parse(documentStream); -
Trying to compare string array using equals not working
Hi,
im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
if(array.equals(copymearray))
System.out.println("they match");
else
{System.out.println("dont match");}
the trouble is that even though they do match i keep getting dont match, can anyone tell me why?try
if (Arrays.equals(array, copymearray))
System.out.println("they match");
else
{System.out.println("dont match");}
Maybe you are looking for
-
Advice Needed for Video Capture Device
Hi, I'm looking to buy a USB (or Firewire if they exist) video capture device that can take S-Video and composite connections. Could someone recommend me best one under $150 that is compatible with Snow Leopard? Also, and more importantly, does anyon
-
The new column designed not appears in the form
Dear All Gurus/Experts, I created new column directly in the database stored in the SQL server 2000,in table IGN1, right click --> select design table, then right click --> insert column, I write U_copqty, numeric data type, 9 is its length and allow
-
Text direction button in indesign 6 seems to be missing
Have been googling how to use arabic text in InDesign 6. I need to create a brochure with text in both Arabic and English. Found section on Adobe World-Ready Paragraph composer - but then when going to set the text direction as in the tutorial - the
-
Final Cut Pro 7.0.3 Crash on startup (No error message)
I have Final Cut Pro 7 installed on one of my computers. I tried to copy the app over to another computer of mine (I don't currently have the original disc with me) and put in the same serial key/registration info etc. It all seems to work fine unti
-
1242 AP stuck in oper down status
Hello, I recently deployed a 1242a\b\g AP. I can see it in WCS (version 4.1). However, the radio's are stuck in a oper down status. At first I was getting an error that the power was insufficient. It is set up with an ethernet power injector. I switc