Need help in writing regular expressions involving \w
Hi,
Here is my requirement .
I have a string : GTA - 12AB TRA - 12AB
I need a regex that represent above string.
GTA - Constant - This wont change
12AB - This will be \w (alphanumeric)
Here I cannot have TRA within this 4 characters.
The question is :
How can I write an expression which says it can be a word(the positions where I have 12AB in example) but not TRA in sequence.
Is this doable?
Thanks in advance.
Use lookarounds: [http://www.regular-expressions.info/lookaround.html]
The regex:
(?!.?TRA).{4}matches any 4 characters (except line breaks) that does not contain 'TRA'.
Similar Messages
-
Need help in unix regular expressions
Hi All,
I'm new to shell scripting. Please help me in achieving this
I am trying to a find regular expression that need to pick a file with begin with the below format and mask variable is called in xml file.
currently the script accepts:
mask="CLIENT_ID+'_ADHSUITE_IN_'+date2str(now,'MMddyy','US/Eastern')+'.txt'"
But it should accept in the below format
2595_ADHSUITE_IN_ANNWEL_030309_2009-02-10_15-12-46-000_648.TXT715.outpgp_out
where CLIENT_ID=2595. How to place wild card character '*' in the below to accept file in the above format. here is what i made changes.
mask="CLIENT_ID+'_ADHSUITE_IN_'*+date2str(now,'MMddyy','US/Eastern')*+'.TXT'*+'.outpgp_out'"
Please help.
ThanksI believe your statement is being passed over twice:
First Pass: (This is done by something like javascript)
CLIENT_ID+'_ADHSUITE_IN_'+'.*'+date2str(now,'MMddyy','US/Eastern')+'.*'+'.TXT'+'.*'+'.outpgp_out'In this pass the variables and functions that are enclosed in literals are processed:
(1) CLIENT_ID is replaced by 2595 or whatever is current value is:
(2) date2str(now,'MMddyy','US/Eastern') gets replaced by 040609 (if the current time now is 4th april 2009).
So at the end of this first pass we have a string:
2595_ADHSUITE_IN_.\*040609.\*.TXT.*.outpgp_outThis string at the end of the first pass is a Posix basic regular expression. (ref: [http://en.wikipedia.org/wiki/Regular_expression] ) accessed at time of post).
This is the string I put in the Regular Expression text box on [http://www.fileformat.info/tool/regex.htm]
and it matches "2595_ADHSUITE_IN_ANNWEL_040609_2009-01-27_17-02-28-000_631.TXT715.outpgp_out" for me (though I prefer my egrep test).
I hope this is somewhat clearer. Remember I have very little information about your system/application and I make big guesses.
NB: (I should thank Frits earlier for pointing my sloppiness between wildcards (for eg unix shell filename expansion) and regular expressions).
For the second pass this used to compared other strings to see -
Need help starting with regular expressions
Hi,
looked through the tutorials, and some stuff online and still having trouble.
I've done a fair amount of modifying xml files with perl, and want to do the same thing with java.
I'm writing this at work, and we don't have the 1.5 jdk installed, so I can't use the Pattern and Match objects.
Here's some code I wrote:
package pack1;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class PlantTest {
* @param args
* @throws Exception
public static void main(String[] args) throws Exception {
// get file to read from
java.io.File infile = new java.io.File("plant.xml");
FileReader infileReader = new FileReader(infile);
BufferedReader bInfile = new BufferedReader(infileReader);
//get basic file info
System.out.println("does the file exist? " + infile.exists());
System.out.println("file is located at: " + infile.getAbsolutePath());
System.out.println("file was last modified: " + new java.util.Date(infile.lastModified()));
// create a pattern
String match = "<COMMON>";
String line = bInfile.readLine();
while (line != null){
//System.out.println(bInfile.readLine());
if (line.matches(match)){
System.out.println("match made: " + line);
bInfile.close();
infileReader.close();
}I want the "match" object to be the equivalent of this in perl:
(I realize I don't have the output set up in the code above, I was going to add it later, for now I just want to make the match and print something on the console)
m/<COMMON>([^<]+)</COMMON>/i;
$common = $1;
print HTML "<p>Common Name: $common\n";here's a snippet of xml:
<PLANT>
<COMMON>Bloodroot</COMMON>
<BOTANICAL>Sanguinaria canadensis</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.44</PRICE>
<AVAILABILITY>031599</AVAILABILITY>
</PLANT>(I cribbed that xml from the w3c site)
thanks in advance,
bp
Message was edited by:
badpersonouch. 1.3.1...
That's here at work, I'm kind of nervous about
downloading another jdk, will there be a conflict?Google for Jakarta ORO regex. It is about the same speed as Java regex and works well with JDK1.3.1 . -
Need help in writing data from JSP to excel
Hi ,
I need help in writing the data from JSP to excel.I somehow able to retrieve the data into excel but unable to get the required format.
For eg: The amount should be displayed in 0.00 format .when i am exporting it to excel it is displaying as 0 :( .
I am using the following code in JSP.
"out.print(amt + '\t');"
Would like to know if there is any otherway where in i can get my requirement.
Thanks
TomHi,
Try using format part of the JSTL tag libs.
Syntax :
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber value="40" pattern="$#,##0.00"/>
I need help in writing the data from JSP to excel.I
somehow able to retrieve the data into excelHow do u convert the jsp to excel?
One way to convert the jsp page to excel, is to render it as an excel appl instead of html. Set the content type of the response to application/ms-excel.
response.setContentType("application/ms-excel")Hope this Helps.... -
Need help for writing extract program
hi
i need help for writing extract program to retriew data from legacy system.
i already developed bdc programs for me31k and me21.
my requirement is to write extract program s for those t.codes.
to retriew data from legacy system and stored in flat file.i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
You haven't posted ANY 'java program' for us to help with.
The forum is NOT a coding service. It is to help you with YOUR code.
Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment. -
Help with Understanding Regular Expressions
Hello Folks,
I need some help in understanding the Regular Expressions.
-- This returns the Expected string from the Source String. ", Redwood Shores,"
SELECT
REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
',[^,]+,', 1, 1) "REGEXPR_SUBSTR"
FROM DUAL;
REGEXPR_SUBSTR
, Redwood Shores,
However, when the query is changed to find the Second Occurrence of the Pattern, it does not match any. IMV, it should return ", CA,"
SELECT
REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
',[^,]+,', 1, *2*) "REGEXPR_SUBSTR"
FROM DUAL;
REGEXPR_SUBSTR
NULLCan somebody help me in understanding Why Second Query not returning ", CA,"?
I did search this forum and found link to thread "https://forums.oracle.com/forums/thread.jspa?threadID=2400143" for basic tutorials.
Regards,
P.PurveshK wrote:
Can somebody help me in understanding Why Second Query not returning ", CA,"?With your query...
SELECT
REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA,aa',
',[^,]+,', 1, *2*) "REGEXPR_SUBSTR"
FROM DUAL;You are looking for patterns of "comma followed by 1 or more non-comma chrs followed by a comma."
So, let's manually pattern match that...
'500 Oracle Parkway, Redwood Shores, CA,aa'
^ ^
| |
|
|
Here to here is the
first occurence.So the second occurance will start searching for the same pattern AFTER the first occurence.
'500 Oracle Parkway, Redwood Shores, CA,aa'
^
|
i.e. the search for the second occurence starts heretherefore the first "," from that point is...
'500 Oracle Parkway, Redwood Shores, CA,aa'
^
|
hereand there is nothing there matching the pattern you are looking for because it only has the
"comma follwed by 1 or more non-comma chrs"... but it doesn't have the "followed by a comma"
...so there is no second occurence, -
Hi,
Please help in writing a UDF for these fields in mapping, which I need for the object Iu2019m doing currently.
The fields are like this:
1) batch_no = "TRUNC((GetMaxObjid('x_txn_sap_parts')-POWER(2,28))/5000)+1",
2) lot_id = "TRUNC((GetMaxObjid('x_txn_sap_parts')-POWER(2,28))/500)+1",
3) How to use JDBC connection factory class in the UDF.
Some logic I can provide which I know i.e. Power (2, 28) means 2 to the power of 28 (2 multiplied 28 times), Trunc means truncate, X_TXN_SAP_Parts is a database table.The Target fields are Batch_no, lot_id & Objid.Actually, objid is mapped initially to a source field i.e. Object ID and in this function it is only being used for the calculation of the batch_no.
Thanks in Advance,
Sreedhar.Hi,
Following with my query I've tried to use this code but still I'm unable to execute the mapping.
import java.util.*;
import com.sap.aii.mapping.lookup.*;
import com.sap.aii.mapping.lookup.*;
DataBaseAccessor accessor = null;
DataBaseResult JDBCOutPayload = null;
String BusinessSystem="clarify_dev_bizsys";
//give your business system having channel name
String CommunicationChannel="JDBC_TO_CDEV";
//give your channel name
String InputPayload= " select X_TXN_PRE_SITE_XFACE.nextval from dual;";
//give your sql query
try {
Channel channel =
LookupService.getChannel(BusinessSystem,CommunicationChannel);
accessor = LookupService.getDataBaseAccessor(channel);
DataBaseResult resultSet = accessor.execute(InputPayload);
for(Iterator rows = resultSet.getRows();rows.hasNext();){
Map rowMap = (Map)rows.next();
Object cValue = rowMap.get("batchno");
//field name of field required , as in database
catch (Exception e) {}
finally {
if (accessor != null)
accessor.close();
result.addValue((String)cValue);
--> I don't know what are the parameters to be used and how to be used in the UDF because this is the first time I'm writing a UDF.
--> The problem in using this query is that both OBJID & BatchNo. are on the target side and the value for the OBJID is retrieved by a SELECT query from the database.
Kindly help me how to resolve this query of mine.
Thanks in Advance.
Sreedhar. -
Need help with writing a query with dynamic FROM clause
Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
Any pointers will be appreciated.
Thanks
rogers42Hi,
rogers42 wrote:
Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'
Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
-- Preliminary Query:
COLUMN my_table_name_col NEW_VALUE my_table_name
SELECT table_name AS my_table_name_col
FROM all_tables
WHERE owner = 'SCOTT'
AND table_name LIKE 'E%';
-- Main Query:
SELECT COUNT (*) AS cnt
FROM scott.&my_table_name
;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
Edited by: Frank Kulash on Aug 11, 2011 2:30 PM -
Need helping in writing query for finding percentage of duration
Can any one please help in writing query for this.
The table is like this :-
ID Region Month Duration
I1 R1 Jan 80
I2 R2 Jan 70
I3 R1 Jan 70
I4 R3 Jan 40
I5 R1 Feb 80
I6 R2 Feb 30
I7 R3 Mar 100
I want to write a query to find
% of duration for each and every region against each and every month.
Please help in solving this query. I am in urgent need of this.
Thanks in advance.I also have to do in MS Access 2003You also have to ask into an other forum since here it's an Oracle forum, to try to find Oracle solution.
Nicolas. -
Urgent help regarding Java regular expressions.
hello everyone,
I am trying to parse a html file which contains
dyn.Img("http://www.boston.com/news/nation/articles/2007/06/21/bill_clinton_takes_bigger_campaign_role&h=306&w=410&sz=13&hl=en&start=43","","QFo9lqKeMR7uzM:","http://cache.boston.com/resize/bonzai-fba/AP_Photo/2007/06/21/1182410228_1931/410w.jpg","125","93","\x3cb\x3eBill Clinton\x3c/b\x3e takes bigger campaign \x3cb\x3e...\x3c/b\x3e","","","410 x 306 - 13k","jpg","www.boston.com","","","http://tbn0.google.com/images","1")
the given above function many times. I have to fetch the whole functions into an array. So i have to write a regular expression which recognises the whole above string.
Can anyone please help me.
Thank you,
chaitanyawell if this is all you want
http://cache.boston.com/resize/bonzai-fba/AP_Photo/2007/06/21/1182410228_1931/410w.jpg
You can always substring it like chuck said
***BUT all the images would have to be .jpg for this to work***
back = we.indexOf(".jpg");
int x = 0;
while (back < web.lastIndexOf(".jpg"))
back = web.indexOf("http",back+1);
picture[x] = web.substring(front, back);
x++;
front = back;
} Might not be the best code but it worked with a website i had to parse
Message was edited by:
mark07 -
Need to remove Commas REgular Expressions?
How can I use java to remove commas from a number.
1,000 string
need it to be
1000
can I pass it through some sort of regular expression?I was attempting to do it with regular expressions to learn how to do them better.
Thanks for your good comment.
nupevic -
Hi All,
I want to use the regular expression for the following statement, So how should I write that.
If any string that is of letter (mr,Mr,mr.,Mr.,Mr .,mr .) should be trated as Male or M. Like wise for female also.
DECODE(title,'MR','M','MR.','M','MISS','F','MRS','F','MRS.','F','MS.','F','Unknown') AS male_femalePlease can anyone help to write the REG EXP?
thanks.Hi Sid,
Assuming 'Mr .' is OK but 'Mr ' is not, you can use
with t as (
select 'MR' as title from dual union all
select 'Mr.' as title from dual union all
select 'Mr .' as title from dual union all
select 'Mr ' as title from dual union all
select 'MISS' as title from dual union all
select 'MRS' as title from dual union all
select 'MRS.' as title from dual union all
select 'ms.' as title from dual union all
select 'MISSTAKE' as title from dual
select
title
, case
when regexp_like(title,'^MR( \.|\.?)$','i') then 'M'
when regexp_like(title,'^(MISS|MRS\.?|MS.)$','i') then 'F'
else 'Unknown'
end as Male_Female
from t
TITLE MALE_FEMALE
MR M
Mr. M
Mr . M
Mr Unknown
MISS F
MRS F
MRS. F
ms. F
MISSTAKE Unknown Regards,
Bob -
Need help in writing a vbscript
Hi,
I need help in wring a vbscript. I have serached for the vbscript on the net, but could not find any.
I need to add a file to an msi using vbscript. - That's the requirement.
For this I have done the following with the help of vbscript.
1. With the insert statement I inserted a new copmonent in the FeatureComponent Table.
2. Now the next thing I did is, I inserted a new row in the File table using insert statement again. The file is uncompressed.
3. Since the file is a non-version file I also added a row in the MSIFileHash table.
4. Also, now added the Component in the component table.
After doing this I am able to see the chnages in the mst, however whrn I try to install it I get an error 2725 (Invalid database tables).
Can somebody please post a vbscript which can add a file to an msi?Hi All,
Thanks for all your responses.
Yes, It is not so easy. I never said it was. Thanks for pointing out Orca. We use Orca on a daily basis.
What exactly I am looking at, is this.
We have some standard applications which needs to be repackaged every month. The repackaging process is same and does not change at least for these packages. So I was actually looking at automating these things.
What I did so far.
First we have created an object for Windows installer. I have then taken a copy of the original msi and then opened the database of this temporary msi database in transact mode. Once the database is opened we can use select, insert, update
and delete statements to update the database.
I could successfully add a registry to the msi. The component was also added successfully to the component table. I also could make changes to the Property table.
The tricky part comes with the addition of file to the file table.
The addition of file requires the following steps.
1. Add a new row to the file table. This can be done with the Insert statement.
2. We then need to associate the file to a new component or any other component already existing in the msi. In my case I am creating a new component.
3. We then have to associate this components to a feature in the FeatureComponents table.
4. Since the file I am adding is a non-versioned file, a new row also has to be added to the MSIFILEHASH table.
I could see the changes that I have done using the mst. But when I try to install the msi with the mst, I get the error 2725. I checked everything. All the other steps except for the file addition works fine.
To check whether I am indeed right, I have did this.
Skipped the file addition part to the msi. Every other change that I make works and I am able to install the msi with the mst successfully.
For obvious security reasons I will not be able to share the vbscript with you. If you guys think, that this is not a right forum for this question, please let me know the right forum. I have been stuck with this issue from the past 6 months. Any help would
really be appreciated. -
Need help in writing a vbs script
I am very new to scripting and need help in scripting the following:
When the Windows 7 machine boots up or a user logs on (easy to do with GPO), I want to execute a script that starts some services
ONLY if the length of the computer name is less than or equal to 15 else it should exit. It has to be done in the background without any user interaction.
The script should be able to work for both x86 and x64 version of Win7.
Any help would be greatly appreciated.
Thanks in advance.
JD
JDHi,
I highly recommend that you skip VBScript and learn PowerShell instead. This is pretty trivial in PowerShell:
If ($env:COMPUTERNAME.Length -le 15) {
# Do stuff
# HINT: Look into Start-Service
Write-Host "Under limit: $env:COMPUTERNAME"
} Else {
# Do optional stuff
Write-Host "Over limit: $env:COMPUTERNAME"
(OT: jrv - happy? =])
If you must stick with VBScript for some odd reason, here's an example to get you started:
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputerName = wshNetwork.ComputerName
If Len(strComputerName) <= 15 Then
'Do stuff here when the name is short enough
WScript.Echo "Under limit: " & strComputerName
Else
'Do stuff here when the name is too long (only if you want to)
WScript.Echo "Over limit: " & strComputerName
End If
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/services/
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
Help with java regular expressions
Hi all ,
i am going to match a patternstring against an input string and print the result here is my code:
import java.util.regex.*;
import java.util.*;
public class Main {
private static final String CASE_INSENSITIVE = null;
public static void main(String[] args)
CharSequence inputStr = "i have 5 years FMCG saLEs exp on java/j2ee and i worked on java and j2ee and 2 projects on telecom java j2ee domain with your with saLEs maNAger experience of java j2ee and c# having very good on c++ exposure in JAVA"
String patternStr = "\"java j2ee\" and \"c#\"";
StringTokenizer st = new StringTokenizer(patternStr,"\",OR");
Matcher matcher=null;
while(st.hasMoreTokens()){
String s=st.nextToken();
Pattern pattern = Pattern.compile(s,Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(inputStr);
while (matcher.find()) {
String result = matcher.group();
if(!result.equalsIgnoreCase(" "))
System.out.println("result:"+result);
when i compile this code i am getting the expected result...ie
result:java j2ee
result:java j2ee
result: and
result: and
result: and
result: and
result: and
result: and
result:c#
but when i replace String patternStr = "\"java j2ee\" and \"c#\""; with
String patternStr = "\"java j2ee\" and \"c++\""; i am just getting c in the result instead of c++ ie i am getting result :
result:java j2ee
result:java j2ee
result: and
result: and
result: and
result: and
result: and
result: and
result:C
result:c
result:c
result:c
result:c
result:c
result:c
In the last lines i should get result:c++ instead of result: c
Any ideas please
ThanksIn the last lines i should get result:c++ instead of result: cThe regular expression parser considers the plus sign '+' a special
character; it means: one or more times the previous regular expression.
So 'c++' means one or more 'c's on or more times. Obviously you don't
want that, you want a literal '+' plus sign. You can do that by prepending
the '+' with a backslash '\'. Unfortunately, the javac compiler considers
a backslash a special character and therefore you have to 'escape'
the backslash also, by adding another backslash. The result looks
like this:"c\\+\\+"kind regards,
Jos
Maybe you are looking for
-
My ihpone 4 wont turn on goes straight to itunes screen
i recently tried to update my iphone 4 and it told me i have restore my iphone in order to update.I put my iphone in recovery mode and connected to itunes now i cant get out of itunes. everytime i turn my phone on it goes staright to the itunes scree
-
I am running iPhoto '09 (v8.1.1) on MacOS 10.6.2. When I double click on many of the thumbnails in my iPhoto library, rather than the image opening to full size, the screen goes black. This phenomenon seems to occur randomly. However, once it occurs,
-
Is my internal hard drive dead?!? (iMac mid-2007)
Hi everyone, My aluminum iMac (mid-2007) is behaving strangely recently. I'm suspecting some internal hard drive failure. Here are the symptoms: 1) Difficult wakeups from sleep mode: two times out of three, the spinning beachball appears on each open
-
The window opens and I get the download complete message but the info is not visible. Also the button at the bottom to clear window is not active. I have downloaded Adobe Reader but cannot find the file so I can install the reader. Something, somewhe
-
Com.sapportals.km.explorer-search iview can't run.
Hi , After we upgrade KMC SP2 from Patch Level 4 hotfix 3 to Patch Level 5 hotfix 4, the iview sap.sapportals.km.explorer-search can't run. Our EP version is EP SP2 Patch 41, J2EE Engine is SP41, Java library is version 20. ============== The error m