Regular Expressions - Logical AND
I know this isn't Java, and it's not really an algorithm, but I can't figure this out. I hope amongst this bright group of developers someone can help me.
I am searching for a regular expressions that will match a series of words.
Example:
Given the words: "ship book"
What regular expression could be used to find both the word "ship" and the "book"?
I have found one expression that will do it ... ship.*book|book.*ship
But that expression doesn't scale. Does anyone know of a better way?
Thanks,
BacMan
Hi,
How about something like:
public class Regexp1
private static final Pattern all = Pattern.compile(
"^(\\s*\\b(monkey|turnip|ship|book)\\b\\s*)*$" );
private static final Pattern p = Pattern.compile(
"\\s*\\b(monkey|turnip|ship|book)\\b\\s*" );
public static void main( String[] argv )
find( "ship book turnip monkey" );
find( "monkey giraffe mango" );
find( "ship shipship ship" );
public static void find( String text )
System.out.println( "Text: " + text );
Matcher m = p.matcher( text );
System.out.println( "Matches all: " + all.matcher( text ).matches() );
while ( m.find() )
System.out.println( "Matching word: '" + m.group(1) + "'" );
}which will produce this when run:
Text: ship book turnip monkey
Matches all: true
Matching word: 'ship'
Matching word: 'book'
Matching word: 'turnip'
Matching word: 'monkey'
Text: monkey giraffe mango
Matches all: false
Matching word: 'monkey'
Text: ship shipship ship
Matches all: false
Matching word: 'ship'
Matching word: 'ship'Pattern all tests to see if all the words are present.
Pattern p finds each matching word and ignores others.
Ol.
Similar Messages
-
The Regular Expression anchors, "^" and "$" do not work for me in Dreamweaver
I am using the Find and Replace feature of Dreamweaver 8 and especially the "Use Regular Expressions" setting. But I have never been able to make the Regular Expression anchors "^" and "$" work at all. This are supposed to fix a match at the beginning or ending of a line or input. But if I search even something as elementary as "^ ", or " $", it can't seem to find them.
Am I missing something? Can somebody give me an example of this working?
Any and all tips or clues would be appreciated.Welcome to Apple Discussions and Mac Computing
Definitely an E-bay issue. The coding on the page is not Safari-friendly. Firefox, as you discovered, in this instance is the better choice. -
Regular Expressions, include and exclude xml-files
Hi!
I have a javaprogram that should read xml-files from a directory. The program could contain several types of files but it should only read files with a certain pattern.
The file names will look like this:
"resultset_27_23.xml"
where the numbers will change, but the rest of the file name is the same (resultset_XX_XX.xml).
But in the same directory it will also be files with the following pattern:
"resultset_27_23_attachment1.xml"
Here, the numbers could change in the in the same way as the files above, and the number after the text (attachment) could also differ from file to file.Those files should not be read by the program.
I have tried to write a regular expression pattern that only reads the first file types, and exlcudes the other ones, but it won�t work.
Does anyone have a solution to my problem? It is possible to use either just one pattern, or two patterns; one for the files that should be included, and one for the files that should be excluded.So you only want files that match resultset_XX_XX.xml? Will the numbers always be two digits each? Assuming so:
"^resultset_\\d\\d_\\d\\d.xml$"Depending which methods you use, the ^ and $ may or may not be necessary.
If that's not what you meant, please clarify. -
Regular Expressions find and replace
Hi ,
I have a question on using Regular Expressions in Java(java.util.regex).
Problem Description:
I have a string (say for example strHTML) which contains the whole HTML code of a webpage. I want to be able to search for all the image source tags and check whether they are absolute urls to the image source(for eg. <img src="www.google.com/images/logo.gif" >) or relative(for eg. <img src="../images/logo.gif" >).
If they are realtive urls to the image path, then I wish to replace them with their absolute urls throughout the webpage(in this case inside string strHTML).
I have to do it inside a servlet and hence have to use java.
I tried . This is the code. It doesn't match and replace and goes inside an infinite loop i.e probably the pattern matches everything.
//Change all images to actual http addresses FOR example change src="../images/logo.gif" to src="http://www.google.com/../images/logo.gif"
String ddurl="http://www.google.com/";
String strHTML=" < img src=\"../images/logo.gif\" alt=\"Google logo\">";
Pattern p = Pattern.compile ("(?i)src[\\s]*=[\\s]*[\"\']([./]*.*)[\"\']");
Matcher m = p.matcher (strHTML);
while(m.find())
m.replaceAll(ddurl+m.group(1));
what is wrong in this?
Thanks,
RajivRight, here's the full monte (whatever that means):import java.util.regex.*;
public class Test1
public static void main(String[] args)
String domain = "http://www.google.com/";
String strHTML =
" < img src=\"images/logo.gif\" alt=\"Google logo\">\n" +
" <img alt=\"Google logo\" src=images/logo.gif >\n" +
" <IMG SRC=\"/images/logo.gif\" alt=\"Google logo\">\n" +
" <img alt=\"Google logo\" src=../images/logo.gif>\n" +
" <img src=http://www.yahoo.com/images/logo.gif alt=\"Yahoo logo\">";
String regex =
"(<\\s*img.+?src\\s*=\\s*) # Capture preliminaries in $1. \n" +
"(?: # First look for URL in quotes. \n" +
" ([\"\']) # Capture open quote in $2. \n" +
" (?!http:) # If it isn't absolute... \n" +
" /?(.+?) # ...capture URL in $3 \n" +
" \\2 # Match the closing quote \n" +
" | # Look for non-quoted URL. \n" +
" (?!http:) # If it isn't absolute... \n" +
" /?([^\\s>]+) # ...capture URL in $4 \n" +
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.COMMENTS);
Matcher m = p.matcher(strHTML);
StringBuffer sbuf = new StringBuffer();
while (m.find())
String relURL = m.group(3) != null ? m.group(3) : m.group(4);
m.appendReplacement(sbuf, "$1\"" + domain + relURL + "\"");
m.appendTail(sbuf);
System.out.println(sbuf.toString());
}First off, observe that I'm using free-spacing (or "COMMENTS") mode to make the regex easier to read--all the whitespace and comments will be ignored by the Pattern compiler. I also used the CASE_INSENSITIVE flag instead of an embedded (?i), just to remove some clutter. By the way, your second (?i) was redundant; the first one would remain in effect until "turned off" with a (?-i). Another way to localize a flag's effect by using it within a non-capturing group, e.g., (?i:img).
As jaylogan said, the best way to filter out absolute URL's is by using a negative lookahead, and that's what I've done here. The problem of optional quotes I addressed by trying to match first with quotes, then without. The all-in-one approach might work with URL's, since they can't (AFAIK) contain whitespace anyway, but the alternation method can be used to match any attribute/value pair. It's also, I feel, easier to understand and maintain. Unfortunately, it also means that you can't use replaceAll(), since you have to determine which alternative matched before doing the replacement, but the long version is still pretty simple (especially when you can just copy it from the javadoc for the appendReplacement() method, as I did). -
Regular Expression Find and Replace with Wildcards
Hi!
For the world of me, I can't figure out the right way to do this.
I basically have a list of last names, first names. I want the last name to have a different css style than the first name.
So this is what I have now:
<b>AAGAARD, TODD, S.</b><br>
<b>AAMOT, KARI,</b> <br>
<b>AARON, MARJORIE, C. </b> <br>
and this is what I need to have:
<span class="LastName">AAGAARD</span> <span class="FirstName">, TODD, S. </span> <br />
<span class="LastName">AAMOT</span> <span class="FirstName">, KARI,</span> <br/>
<span class="LastName">AARON</span> <span class="FirstName">, MARJORIE, C.</span> <br/>
Any ideas?
Thanks!Make a backup first.
In the Find field use:
<b>(\w+),\s+([^<]+)<\/b>\s*<br>
In the Replace field use:
<span class="LastName">$1</span> <span classs="FirstName">$2</span><br />
Select Use regular expression. Light the blue touch paper, and click Replace All. -
Regular expression: numbers and letters allowed
How can i determine best way following: input string may contain only numbers and letters, letters can be from any alphabet.
Examples:
'123aBc' - correct, only numbers and letters
'123 aBc' - wrong, contains space
'123,aBc' - wrong, contains comma
'öäüõ' - correct, contains letters from Estonian alphabet.
'abc' - correct, contains letters from english alphabet.
I think i should use function "regexp_like" for that, because LIKE-operator can't do such things, correct?
How i should write the regular expression then? I'm new to reg expressions.CharlesRoos wrote:
How can i determine best way following: input string may contain only numbers and letters, letters can be from any alphabet.
Examples:
'123aBc' - correct, only numbers and letters
'123 aBc' - wrong, contains space
'123,aBc' - wrong, contains comma
'öäüõ' - correct, contains letters from Estonian alphabet.
'abc' - correct, contains letters from english alphabet.
I think i should use function "regexp_like" for that, because LIKE-operator can't do such things, correct?
How i should write the regular expression then? I'm new to reg expressions.I'm not too hot on the foreign alphabets, but something like:
regexp_like(txt, '^[[:alpha:][:digit:]]*$')should do it I think. -
Regular Expressions, split(), and the caret
I have a string delimited by the ^ character:
ITEM1^ITEM2^ITEM3
I've tried using:
split("^")
split("\^")
split("\x5E")
All to no avail. I either get "Invalid escape sequence" or I get the whole string. I'm looking to avoid the StringTokenizer way, just because this is neater IMHO.
Is this possible?\ is the escape character for both Java and regex. The first escape character is for Java, so that the second \ will be treated as a literal in Java and passed as-is to the pattern matcher. The second \ is for the regex, so the pattern matcher will treat the ^ as a literal.
-
Regular Expression + Find and Replace
Hey there- I have a question about regExp and the Find and Replace. Basically I want to search a wildcard between a href tag, how would that look, because the code below does not work.
countryLink = "<a href=\"http://www.whateve.com\" target=\"_parent\">";
[code]
countryLink = "([^"]*)";
[code]
Thanks! Any help is appreciated!
Also, how do i add code blocks to this forum?Yes, I meant the <a> tag, but thank you for displaying the href attribute solution as well. This solved my issue. Thanks! Thought I would display what I did with your code incase someone was interested in using this code to convert a javascript string to XML.
query this:
countryLink = "<a href=\"http://www.whateve.com\" target=\"_blank\">";
add this to the Find box:
countryLink = "<a href=\\"([-\w:/.?=&;]+)\\" target=\\"_parent\\">";
add this to the Replace box:
<countryLink>$1</countryLink>
creates an output of this:
<countryLink>http://www.whateve.com</countryLink> -
Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected]Namburi,
When you said you used the Reg Exp tool, did you use it only as
preconfigured by the iMT migrate application wizard?
Because the default configuration of the regular expression tool will only
target the files in your ND project directories. If you wish to target
classes outside of the normal directory scope, you have to either modify the
"Source Directory" property OR create another instance of the regular
expression tool. See the "Tool" menu in the iMT to create additional tool
instances which can each be configured to target different sets of files
using different sets of rules.
Usually, I utilize 3 different sets of rules files on a given migration:
spider2jato.xml
these are the generic conversion rules (but includes the optimized rules for
ViewBean and Model based code, i.e. these rules do not utilize the
RequestManager since it is not needed for code running inside the ViewBean
or Model classes)
I run these rules against all files.
See the file download section of this forum for periodic updates to these
rules.
nonProjectFileRules.xml
these include rules that add the necessary
RequestManager.getRequestContext(). etc prefixes to many of the common
calls.
I run these rules against user module and any other classes that do not are
not ModuleServlet, ContainerView, or Model classes.
appXRules.xml
these rules include application specific changes that I discover while
working on the project. A common thing here is changing import statements
(since the migration tool moves ND project code into different jato
packaging structure, you sometime need to adjust imports in non-project
classes that previously imported ND project specific packages)
So you see, you are not limited to one set of rules at all. Just be careful
to keep track of your backups (the regexp tool provides several options in
its Expert Properties related to back up strategies).
----- Original Message -----
From: <vnamboori@y...>
Sent: Wednesday, August 08, 2001 6:08 AM
Subject: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't
forget about the regular expression potential
Thanks Matt, Mike, Todd
This is a great input for our migration. Though we used the existing
Regular Expression Mapping tool, we did not change this to meet our
own needs as mentioned by Mike.
We would certainly incorporate this to ease our migration.
Namburi
--- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
All--
Great response. By the way, the Regular Expression Tool uses thePerl5 RE
syntax as implemented by Apache OROMatcher. If you're doing lotsof these
sorts of migration changes manually, you should definitely buy theO'Reilly
book "Mastering Regular Expressions" and generate some rules toautomate the
conversion. Although they are definitely confusing at first,regular
expressions are fairly easy to understand with some documentation,and are
superbly effective at tackling this kind of migration task.
Todd
----- Original Message -----
From: "Mike Frisino" <Michael.Frisino@S...>
Sent: Tuesday, August 07, 2001 5:20 PM
Subject: Re: [iPlanet-JATO] Use Of models in utility classes -Pease don't
forget about the regular expression potential
Also, (and Matt's document may mention this)
Please bear in mind that this statement is not totally correct:
Since the migration tool does not do much of conversion for
these
utilities we have to do manually.Remember, the iMT is a SUITE of tools. There is the extractiontool, and
the translation tool, and the regular expression tool, and severalother
smaller tools (like the jar and compilation tools). It is correctto state
that the extraction and translation tools only significantlyconvert the
primary ND project objects (the pages, the data objects, and theproject
classes). The extraction and translation tools do minimumtranslation of the
User Module objects (i.e. they repackage the user module classes inthe new
jato module packages). It is correct that for all other utilityclasses
which are not formally part of the ND project, the extraction and
translation tools do not perform any migration.
However, the regular expression tool can "migrate" any arbitrary
file
(utility classes etc) to the degree that the regular expressionrules
correlate to the code present in the arbitrary file. So first andforemost,
if you have alot of spider code in your non-project classes youshould
consider using the regular expression tool and if warranted adding
additional rules to reduce the amount of manual adjustments thatneed to be
made. I can stress this enough. We can even help you write theregular
expression rules if you simply identify the code pattern you wish to
convert. Just because there is not already a regular expressionrule to
match your need does not mean it can't be written. We have notnearly
exhausted the possibilities.
For example if you say, we need to convert
CSpider.getDataObject("X");
To
RequestManager.getRequestContext().getModelManager().getModel(XModel.class);
Maybe we or somebody else in the list can help write that regularexpression if it has not already been written. For instance in thelast
updated spider2jato.xml file there is already aCSpider.getCommonPage("X")
rule:
<!--getPage to getViewBean-->
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getPage[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getViewBean($1ViewBean.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
Following this example a getDataObject to getModel would look
like this:
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[CSpider[.\s]*getDataObject[\s]*\(\"([^"]*)\"]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[getModel($1Model.class]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
In fact, one migration developer already wrote that rule andsubmitted it
for inclusion in the basic set. I will post another upgrade to thebasic
regular expression rule set, look for a "file uploaded" posting.Also,
please consider contributing any additional generic rules that youhave
written for inclusion in the basic set.
Please not, that in some cases (Utility classes in particular)
the rule
application may be more effective as TWO sequention rules ratherthan one
monolithic rule. Again using the example above, it will convert
CSpider.getDataObject("Foo");
To
getModel(FooModel.class);
Now that is the most effective conversion for that code if that
code is in
a page or data object class file. But if that code is in a Utilityclass you
really want:
>
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
So to go from
getModel(FooModel.class);
To
RequestManager.getRequestContext().getModelManager().getModel(FooModel.class
You would apply a second rule AND you would ONLY run this rule
against
your utility classes so that you would not otherwise affect yourViewBean
and Model classes which are completely fine with the simplegetModel call.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getModel\(]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getModel\(]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getRequestContext().getModelManager().getModel(]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
A similer rule can be applied to getSession and other CSpider APIcalls.
For instance here is the rule for converting getSession calls toleverage
the RequestManager.
<mapping-rule>
<mapping-rule-primarymatch>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-primarymatch>
<mapping-rule-replacement>
<mapping-rule-match>
<![CDATA[getSession\(\)\.]]>
</mapping-rule-match>
<mapping-rule-substitute>
<![CDATA[RequestManager.getSession().]]>
</mapping-rule-substitute>
</mapping-rule-replacement>
</mapping-rule>
----- Original Message -----
From: "Matthew Stevens" <matthew.stevens@e...>
Sent: Tuesday, August 07, 2001 12:56 PM
Subject: RE: [iPlanet-JATO] Use Of models in utility classes
Namburi,
I will post a document to the group site this evening which has
the
details
on various tactics of migrating these type of utilities.
Essentially,
you
either need to convert these utilities to Models themselves or
keep the
utilities as is and simply use the
RequestManager.getRequestContext.getModelManager().getModel()
to statically access Models.
For CSpSelect.executeImmediate() I have an example of customhelper
method
as a replacement whicch uses JDBC results instead of
CSpDBResult.
matt
-----Original Message-----
From: vnamboori@y... [mailto:<a href="/group/SunONE-JATO/post?protectID=081071113213093190112061186248100208071048">vnamboori@y...</a>]
Sent: Tuesday, August 07, 2001 3:24 PM
Subject: [iPlanet-JATO] Use Of models in utility classes
Hi All,
In the present ND project we have lots of utility classes.
These
classes in diffrent directory. Not part of nd pages.
In these classes we access the dataobjects and do themanipulations.
So we access dataobjects directly like
CSpider.getDataObject("do....");
and then execute it.
Since the migration tool does not do much of conversion forthese
utilities we have to do manually.
My question is Can we access the the models in the postmigration
sameway or do we need requestContext?
We have lots of utility classes which are DataObjectintensive. Can
someone suggest a better way to migrate this kind of code.
Thanks
Namburi
[email protected]
[email protected]
[Non-text portions of this message have been removed]
[email protected]
[email protected] -
Hello All,
I come from Perl scripting language background. Perl's regular expressions are rock solid, robust and very fast.
Now I am planning to master Regular Expressions in Oracle.
Could someone please point the correct place to start with it like official Oracle documentation on Regular Expressions, any good book on Regex or may be any online link etc.
Cheers,
Parag
Edited by: Parag Kalra on Dec 19, 2009 11:03 AMHi, Parag,
Look under [R in the index of the SQL language manual|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm#R]. All the regular expression functions and operators start with "REGEXP", and there are a couple of entries under "regular expressions".
That applies to the Oracle 11 and 10.2 documentation. Regular expressions were hidden in the Oracle 10.1 SQL Language manual; you had to look up some similar function (like REGR_SYY, itself hidden under S for "SQL Functions", and then step through the pages one at a time.
Sorry, I don't know a good tutorial or introduction.
If you find something hopeful, please post a reference here. I think a lot of people would be interrested. -
Regular expressions in ActionScript??
I have been looking at the Adobe publication Programming Action Script (pdf) and it
specifies ECMA-262 3rd edition specification. But the specification don't seem to
state exactly what type of regular expression engine and version is used.
Is it POSIX, or PERL compatible regular expressions (or both)?
I have read and used the classic O'Reilly text Mastering Regular Expressions
and coded regular expressions in javascript/php/etc (anywhere regular expressions
could be use, Apache configuration file, other server config files, etc etc etc)
There is a difference in the type of engine used, where as performance is
concerned, as well as the range of syntax valid in a particular implementation.
Thank You
JKhttp://www.regular-expressions.info/javascript.html
-
Regular Expressions to Omit Characters
I am new to Java. I am trying to use regular expressions to omit a pattern. The construct [^abc] can be used to omit a or b or c, but how can I omit the string abc from a regular expression? Many thanks.
Why not use the regular expression "abc" and see if it doesn't match? Or even use this:
boolean matches = (targetString.indexOf("abc") == -1); // == -1 means "not found", so matches become true if abc is not in targetString
if (matches) System.out.println("Yay, no abc in " + targetString + "!");
else System.out.println("Eek, get that abc out of my sight!"); -
What is a Regular Expression?
I have been programming for a couple of years, and I keep hearing people talk about regular expressions and perl like regular excpression. Java has an api for regular expression's, and I would just like some one to lay down the facts and explain to me what they are and how they are used.
Thanks. :)http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/
-
Match beginning of line with Regular Expression
I'm confused about dreamweaver's treatment of the characters
^ and $ (beginning of line, end of line) in regex searches. It
seems that these characters match the beginning of the file, not
the beginning of the various lines in the file. I would expect it
to work the other way around. A search like:
(^.)
should match every line in the file, so that a find/replace
could be performed at the beginning of each line, like this:
HELLO$1
which would add 'HELLO' at the start of each line in the
file.
Instead, this action only matches the first character of the
file, sticks 'HELLO' in front of it, and then quits (or moves on to
the next file). The endline character $ behaves in a similar
fashion, matching only the end of the file, not the end of each
line.
I've searched, and all the literature about regular
expressions in dreamweaver seems to indicate that I'm expecting the
correct behavior:
www.adobe.com/devnet/dreamweaver/articles/regular_expressions_03.html
quote:
^ Beginning of input or line ^T matches "T" in "This good
earth" but not in "Uncle Tom's Cabin"
$ End of input or line h$ matches "h" in "teach" but not in
"teacher"
Thanks for any insight, folks.Hi Winston,
I am still digesting the material from the regular expression book and will take sometime to become proficient with it.
It seems that using groupCount() to eliminate the unwanted text does not work in this case, since all the lines returned the same value. Ie 3 posted earlier. This may be because the patterns are complex and only a few were grouped together. Otherwise, could you provide an example using the string posted as opposed to a hyperthetic one. In the meantime, at least one solution have been found by defining an additional special pattern “\\A[^%].*\\Z”, before combining / intersecting both existing and the new special pattern to get the best of both world. Another approach that should also work is to evaluate the size of String.split() and only accept those lines with a minimum number of tokens.
Anyhow, I have come a crossed another minor stumbling block in the mean time with the following line, where some hidden characters is preventing the existing pattern from reading it:
o;?Mervan Bay 40 Boyde St 7 br t $250,000 X West Park AE
Below is the existing regular expression that works for other lines with the same pattern but not for special hidden characters such as “o;?”:
\\A([A-Z][a-z]*){1,2} [0-9]{0,4}/?[0-9]{0,4}-?[0-9]{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La [0-9] br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}\\ZIs it possible to come up with a regular expression to ignore them so that this line could be picked up? Would also like to know whether I could combine both the special pattern “\\A[^%].*\\Z” with existing one as opposed to using 2 separate patterns altogether?
Many thanks,
Jack -
Regular expression to change erroneous JSTL information fails
// THIS IS WHAT TO LOOK FOR: <c:param name="[name]" value="<%= [value] %>" />
if (stuff.indexOf(".com/jstl") >= 0) {
stuff = stuff.replaceAll(".com/jstl", ".com/jsp/jstl");
Matcher matcher = Pattern.compile("(<c:param[ \\t]+name=\"[^\"]+\"[ \\t]+value=\")<%=([^%=\"]+)%>(\".*$)").matcher(stuff);
if (matcher.matches()) {
matcher.replaceAll("$1\${$2}$3");
}What I am trying to do is very simple but brain-numbing for the past few days. I found out that about 100 different JSP scripts have the wrong information:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:import name="header.jsp" context="/globals" >
<c:param name="path" value="<%= path %>" />
</c:import>What I am supposed to apparently have is this:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import name="header.jsp" context="/globals" >
<c:param name="path value="${path}" />
</c:import>
{code}
But changing 100 scripts manually is extremely hard especially when you don't know where they are among the 250 other scripts within the entire portal. Thus, I wrote a Java class I can run from the command-line to do this for me, however, the regular expression pattern I selected to make the change constantly fails.
I can't seem to figure out why it fails as I've tested using various online regular expression testers and it's the most accurate assuming Java uses POSIX.
Help very much appreciated, thanksPhil_The_Lifeless_Programmer wrote:
I don't see how you proposed that solution, unless you proposed it in a way that I could not understand, it sounded as if you were trying to point out flaws w/o a solution.I pointed out the flaws along a solution. You specified only one backslash in the replacement pattern. A backslash is an escape character in String. You need to add one more backslash to represent an actual backslash. You are invoking Matcher#replaceAll() without doing anything with its result and expected that changes are reflected in 'stuff'. I pointed that out too, along with the recommendation that you need to assign and use its return value.
It might be my English or your stressfull head that you misunderstood it. But don't complain that I didn't give the solution. Or do you only qualify complete code snippets as a solution?
I forgot to also mention that you have to run the Java class program multiple times manually in spite of the while loop. It appears to only replace the very last instance of the pattern in the file and nothing else. If you manually run it multiple times only then does it replace each line, from last to first.Your regex might just be wrong, it look like that it only matches the first occurrence. I am not an advanced regex expert, so I can't say much about this. Consider reposting this question (in a more friendly form!) in the Java Programming forum. There walk a lot of regex guru's around, e.g. uncle_alice, sabre150 and prometheuzz.
Good luck, man. And please take a breathe.
Maybe you are looking for
-
After upgrading to Lion, my Macbook Air's built in iSight camera has disappeared. I'm not sure how to get it recognized again. Help -Sami
-
This device is no longer eligible for creating a free icloud account
After using it for a while an iPad 2 that was given to me by my Boss, I restored this iPad and gave it to my daughter. She encountered the error above during her set-up while creating her own iCloud account to the iPad. What shall we do?
-
Using Jmagick to create Thumbnail of video file
Hello , I have used Imagemagick to create the thumbnail of video file, but it takes a lot of time to generate the thumbnail. So, is there anyway to capture thumbnail a bit faster than it does? Thanks in Advance.
-
Light leakage question, need help...
I bought an iPad 4th Generation 3 weeks ago an it was fine or maybe I don't see any defects before... Then yesterday I started to notice the light leakage in several spot like on the left side of the screen and on the corner near the speaker... Is it
-
Problem in deskjet D-2360 printer
the catrigre carrier of my printer D-2360 is not stable at the center it is moving either side randomly