Searching in reverse with regular expressions
I have recently constructed a "Find" dialog for my editor and would like to support the use of regular expressions (for people who know more about them than I do.) I have radio buttons that allow the user to search down (from the current caret position to the end of the document) or up (from the current caret position to the beginning of the document.)
I have it working fine with literal text via String.indexOf() and String.lastIndexOf(), but I'm not sure how to implement an "upwards" search using regular expressions. It seems that java.util.regex only provides for searching from the current caret position downwards. Any suggestions?
two not-very-good-for-big-document suggestions
1) search up by searching down (from the beginning) to the last match before the position searched from
2) when the user asks for a search find all matches, number them and keep the index in the doc where they were found, then look up the largest index less than the carets index
you might try constructing succesively larger strings that end at the current caret position, and matching them one by one. If you're near the bottom, and theres no matches, this is also likely to be sloow..
asjf
Similar Messages
-
How to search with regular expression
I make pdx files so that I can search text quickly. But Acrobat doesn't provide a way to search with regular expression. I'm wondering if there is a way that I don't know to search for regular expression in Acrobat Pro 9?
First, Acrobat must "mount" the PDX.
As "Find" does not use the cataloged index, use Shift+Ctrl+F to open the advanced search dialog.
It may be helpful to first enter Acrobat Preferences and for the Search category tick "Always use advanced search options".
Back to the Search dialog - use the drop down menu for "Look In" to pick "Select Index" then, if no PDXs show, click the Add button.
In the Open Index File dialog, browse to the location of the desired PDX and select it.
OK out and use "Return results containing" to pick a "Match ..." requirement or Boolean.
To become familiar with query syntax, for Acrobat, it is good to review Acrobat Help.
http://help.adobe.com/en_US/Acrobat/9.0/Professional/WS58a04a822e3e50102bd615109794195ff-7 c4b.w.html
Be well... -
Grouping & Back-references with regular expressions on Replace Text window
I really appreciate the inclusion of the Regular Expressions in the search & replace feature. One thing I am missing is back-references in the replacement expression. For instance, in the unix tools vi or sed, I might do something like this:
s/\(firstPart\) \(secondPart\) \(oldThirdPart\)/\2 \1 newThirdPart/g
which would allow me to switch the places of firstPart and secondPart, and totally replace thirdPart. If grouping and back-references are already present in the Replace Text window, how does one correctly invoke them?duplicate of Grouping & Back-references with regular expressions on Replace Text window
-
Assistance with Regular Expression and Tcl
Assistance with Regular Expression and Tcl
Hello Everyone,
I recently began learning Tcl to develop scripts for automating network switch deployments.
In my script, I want to name the device with a location and the last three octets of the base mac address.
I can get the Base MAC address by :
show version | include Base
Base ethernet MAC Address : 00:00:00:DB:CE:00
And I can get the last three octets of the MAC address using the following regular expression.
([0-9a-f]{2}[:-]){2}([0-9a-f]{2}$)
But I have not been able to figure out how to call the regular expression in the tcl script.
I have checked several resources but have not been able to figure it out. Suggestions?
Ultimately, I want to set the last three octets to a variable (something like below) and then call the variable when I name the switch.
set mac [exec "sh version | i Base"] (include the regular expression)
ios_config "hostname location$mac"
Thanks for any assistance in advance.
ChrisThis worked for me.
Switch_1(tcl)#set result [exec show ver | inc Base]
Base ethernet MAC Address : 00:1B:D4:F8:B1:80
Switch_1(tcl)#regexp {([0-9A-F:]{8}\r)} $result -> mac
1
Switch_1(tcl)#puts $mac
F8:B1:80
Switch_1(tcl)#ios_config "hostname location$mac"
%Warning! Hostname should contain at least one alphabet or '-' or '_' character
locationF8:B1:80(tcl)# -
Problem with Regular Expression
Hi There!!
I have a problem with regular expression. I want to validate that one word and second word are same. For that I have written a regex
Pattern p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
Matcher m=p.matcher("nikhil nikhil");
boolean t=m.matches();
if (t)
System.out.println("There is a match");
else
System.out.println("There is no match");
The result I am getting is always "There is no match
Your timely help will be much appreciated.
RegardsRam wrote:
ErasP wrote:
You are missing a backward slash in the regex
Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
But this will fail in this case.
Matcher m = p.matcher("Nikhil Nikhil");It is the reason for that *[a-z]*.The OP had [a-z][a-zA-Z]* in his code, so presumably he know what that means and wants that String not to match. -
Get the string between li tags, with regular expression
I have a unordered list, and I want to store all the strings between the li tags (<li>.?</li>)in an array:
<ul>
<li>This is String One</li>
<li>This is String Two</li>
<li>This is String Three</li>
</ul>
This is what have so far:
<li>(.*?)</li>
but it is not correct, I only want the string without the li tags.
Thanks.No one?
Anoyone here experienced with Regular Expression? -
[CC] Search&Replace: Bug only with Regular Expressions
Can you confirm the following behaviour/bug?
Steps to reproduce:
1 Create a new document in DW CC
2 Enter that text in the source code view:
<p>€</p>
3 Open Search&Replace
Field Search in: Current document
Field Search: Text
Field Search (3rd Field): €
Start Search
Result: As expected the "€" is found.
4 [x] Regular Expressions
Start Search
Result: "€" isn't found
Can you reproduce that?
Do you regard that as a bug like me?
If not, why please?
Do you think it is technically impossible for the developers to solve the task?
Do you think the developers forgot to gray out "text" in the choice box and allow regular expressions only in source code?
Thanks.Nice that you like the nick
Sure, I know that I can file a feature wish.
But my main interest in this forum is to know, what other users think about certain features, why they think so, which they miss, which they regard as a bug, ...
When I remember it right, you told me some time ago, that you don't use RegEx.
Than I understand, that everything around that feature is not important for you.
What I like to understand is, why you think the behaviour is logically.
For me it is the opposite.
You get a result with "Scope: Text", "[ ]RegEx".
And you get no result with "Scope: Text", "[x]RegEx".
Incredible strange.
I would appreciate, if you could explain more detailed your view. -
Search with regular expression like this "[^\(]+mytype"
I tried regular expression which find me line which has "mytype" but does not precede with "("
I wrote it like this: [^\(]+mytype
It works perfectly with python reg exp. But it does not work in MSVC 2013 search(ctrl+shift+f). Do you know why? Is it bug?
Is there a way to find variable definition with search function through whole projectHi Vit,
According to your description, you mean that when you use the
ctrl+shift+f shortcut key to search which line has "mytype" word in the whole project from VS2013 IDE like the following screen shot, but it does not work
in VS2013 IDE, am I right?
If yes, could you please provide me a screen shot about how you search the
mytype?
Generally, when we used the
ctrl+shift+f shortcut key to search, it works fine in VS IDE. Therefore, to check if you install some third-party Add-ins impact your VS IDE, I suggest you can search
the mytype in VS safe mode check if you get same issue.
Reference:
http://msdn.microsoft.com/en-us/library/ms241278.aspx
(1)If you did not get same issue, I doubt that you may be install some Add-ins impact the VS IDE, so I suggest
you can try to disable or un-install them and then check this issue again.
(2)If you still get same issue, I suggest you can try to reset the VS setting file or you can try to repair your
VS check this issue again.
In addition, I suggest you can try to use Ctrl + F shortcut key to search the mytype word.
If I misunderstand your issue, please provide me more detail message about your issue.
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to find sunstring with regular expression?
How can I find a substring in a string with a regular expression?
Example:
I have a original string "<tr><th>RecordId: </th><td valign=middle>A4711</td></tr>"
Now i want to extract the value "A4711" from this string with a regular expression. Everything except "A4711" is fixed, the id "A4711" itself is dynamic. How is it possible to get the substring "A4711" of the original string with a regular expression?i wrote a little method with the infos above to get such results:
* Get all substrings of a string that matches a regular expression.
* @param original String to inspect.
* @param regExp Regular expression as search criteria.
* @return All matches of <i>regExp</i> or null if one input parameter is null.
public static String[] getSubstrings(String original, String regExp) {
String[] result = null;
if (original != null && regExp != null) {
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(original);
boolean matchFound = matcher.find();
Vector matches = new Vector();
while (matchFound) {
String match = matcher.group();
matches.addElement(match);
matchFound = matcher.find();
}//next match
int count = matches.size();
result = new String[count];
for (int i = 0; i < count; i++) {
result[i] = (String) matches.elementAt(i);
}//next match
}//else: input unavailable
return result;
}//getSubstrings() -
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 -
I am wondering how to use the _regex in a hidden
<input>. i have searched every where but there is no examples
on how to use this cfml form validation. Its not that i want
alternatives to do the regular expression just how to use it like
this......
if i had the form....
<form.........>
<input name="email">
<input type="hidden" name="email_regex"
value="*/.............">
</form>
How can i have a message if the input email does not coincide
with the regular expression. would i need to use a second
<input type="hidden" name="email_regex_Required"
value="please insert a valid email adress>i am trying to get it to work like this. The validation type
is valid but i have not found anything on how to use it properly.
it like using the
<input type="hidden" name="email_required" value="the
field is blank, please go back and enter a filed">
I know javascript is the best option but if the browser does
not support this then at least in can attempt a alternative method.
All i would like to know is how do i use this validation type and
how can i get it also to produse a error message. as the "value"
field will contain the regular expresion itself. -
Checking a number sequence with regular expressions
Hello,
Suppose I have a text in the pattern:
A1=ha,A2=bla,A3=cha,...
I don't know how many sections of "A#=$" (# denotes number, $ denotes text) will be in the text, but I want to verify that the numbers of the A's form the natural ascending number sequence (i.e 1,2,3,...). I prefer to use regular expressions to do this, but if there's another way, I will be glad to hear it too.
Therefore my question is: How can I use regular expressions to check for a sequence of numbers? I know I can search for groups I've caught previously in the expression, but how can I compute the next number in the sequence from the group and search for the result?
Thank you very much!What I'd do--and I'm not saying this is optimal, just what pops immediately to mind--is have a regex that matches "A(\\d+)=" (assuming the ha, bla, cha can never be "A1" etc.--if they can, you can still do it, but it's more complicated), then you iterate with the Matcher, and each time, you get the Integer.valueOf what you matched. You keep track of the last value, and compare the current to the last. If current is < last (or <= last, depending on your requirements), fail.
Something like this. I don't recall Matcher's methods off the top of my head, so you'll have to fix the details.
Matcher m = Pattern.matcher("A(\\d+)=");
int maxSoFar = Integer.MIN_VALUE;
while (m.matches(input)) {
int current = Integer.parseInt(m.getMatchedField("$1"));
if (current <= maxSoFar) {
// fail
else {
maxSoFar = current;
} maxSoFar = -
Extract values with Regular Expression
How to extract values into [ ] using regular expression.
With data As
Select 'AAAAAA[10] AAA: 19C' Txt From Dual Union all
Select 'XX[450]-10A' Txt From Dual Union all
Select '[5]AVC19C' Txt From Dual Union all
Select 'FVD[120]D2AC' Txt From Dual
)I hope this return
10
450
5
120Thanks in advanceduser11118871 wrote:
Thanks for all.
Hi BluShadow, can you explain what this is doing!?
ThanksSure.
Search for ----------------| /------- Replace the found pattern in the search string with backreference 1
/------------\ /\ (the first thing backreferenced in the search string)
regexp_replace(txt, '^.*\[(.*)\].*$','\1')
|\/\/\--/\/\/|
| \ \ / \ \|
| | | | | |\- End of string
| | | | | |
| | | | | \- Any number of characters
| | | | |
| | | | \- Right square bracket (escaped)
| | | |
| | | \- any characters (backreferenced by round brackets)
| | |
| | \- Left square bracket (escaped)
| |
| \- Any number of characters
|
\- Start of stringEdited by: BluShadow on Jun 29, 2009 2:19 PM -
GUI Based tool for search and replace using regular expression
Hi,
I have developed this small tool which can be used for search and replace in multiple files using reqular expressions.
Features:
1. Full regular expression
2. GUI based with Highlighted results
3. Preview for replace available
4. Pure Java based.
5. Its like unix sed and grep
Please visit below site for download/more information :
http://sourceforge.net/projects/regexsearchrepl/
Thanks,
Hitesh ViseriaI agree with you, it cannot compete grep/sed/awk combination. I couldnt find anything even close to grep/sed for windows which will also have a preview and most important, free. That is what made me write this tool. I am trying to
improve its performance and more features like history etc.
Any suggestions on additional features are most welcome. -
CFFORM (Flash) Validation with Regular Expressions Not Working
I am having troubles getting regular expression validation to
work in a CFFORM. The below code is an extract of a much larger
form, the first name and last name have a regular expression
validation...and it doesn't work!
I'd appreciate any comments/info for help on this, have
searched high and low on information to get this working...but no
joy.
The code is:
<cffunction name="checkFieldSet" output="false"
returnType="string">
<cfargument name="fields" type="string" required="true"
hint="Fields to search">
<cfargument name="form" type="string" required="true"
hint="Name of the form">
<cfargument name="ascode" type="string" required="true"
hint="Code to fire if all is good.">
<cfset var vcode = "">
<cfset var f = "">
<cfsavecontent variable="vcode">
var ok = true;
var msg = "";
<cfloop index="f" list="#arguments.fields#">
<cfoutput>
if(!mx.validators.Validator.isValid(this,
'#arguments.form#.#f#')) { msg = msg + #f#.errorString + '\n';
ok=false; }
</cfoutput>
</cfloop>
</cfsavecontent>
<cfset vcode = vcode & "if(!ok)
mx.controls.Alert.show(msg,'Validation Error'); ">
<cfset vcode = vcode & "if(ok) #ascode#">
<cfset vcode =
replaceList(vcode,"#chr(10)#,#chr(13)#,#chr(9)#",",,")>
<cfreturn vcode>
</cffunction>
<cfform name="new_form" format="flash" width="600"
height="600" skin="halosilver" action="new_data.cfc">
<cfformgroup type="panel" label="New Form"
style="background-color:##CCCCCC;">
<cfformgroup type="tabnavigator" id="tabs">
<cfformgroup type="page" label="Step 1">
<cfformgroup type="hbox">
<cfformgroup type="panel" label="Requestor Information"
style="headerHeight: 13;">
<cfformgroup type="vbox">
<cfinput type="text" name="reqName" width="300"
label="First Name:" validate="regular_expression" pattern="[^0-9]"
validateat="onblur" required="yes" message="You must supply your
First Name.">
<cfinput type="text" name="reqLname" width="300"
label="Last Name:" validate="regular_expression" pattern="[^0-9]"
validateat="onblur" required="yes" message="You must supply your
Last Name.">
<cfinput type="text" name="reqEmail" width="300"
label="Email:" validate="email" required="yes" message="You must
supply your email or the address given is in the wrong format.">
<cfinput type="text" name="reqPhone" width="300"
label="Phone Extension:" validate="integer" required="yes"
maxlength="4" message="You must supply your phone number.">
</cfformgroup>
</cfformgroup>
</cfformgroup>
<cfformgroup type="horizontal"
style="horizontalAlign:'right';">
<cfinput type="button" width="100" name="cnt_step2"
label="next" value="Next"
onClick="#checkFieldSet("reqName,reqLname,reqEmail,reqPhone","new_form","tabs.selectedInd ex=tabs.selectedIndex+1")#"
align="right">
</cfformgroup>
</cfformgroup>
</cfformgroup>
</cfformgroup>
</cfform>quote:
Originally posted by:
Luckbox72
The problem is not the Regex. I have tested 3 or 4 different
versions that all work on the many different test sites. The
problem is it that the validation does not seem to work. I have
changed the patter to only allow NA and I can still type anything
into the text box. Is there some issue with useing Regex as your
validation?
Bear in mind that by default validation does not occur until
the user attempts to submit the form. If you are trying to control
the characters that the user can enter into the textbox, as opposed
to validating what they have entered, you will need to provide your
own javascript validation.
Maybe you are looking for
-
help with nano 7 on windows 8 welcome
-
Possible to install on external USB 2.0 hard drive?
Is it possible? I have leopard installed on my macbook pro, however i need tiger for final cut pro. I am going to buy an external HD, and want to know if i can install tiger onto it? to use.....for the time being for FCP (some plugins not compatible)
-
Business connector developer-Error message 'No IDOC found in input'
Hi, Please note that this query is related to business connector developer not to XI. I have created a flow service based on an IDOC. When I tried to test the service from the business connector developer it gives me an error 'No idoc found in input'
-
Dynamic selection in S_ALR_87012169
Hello everyone. I have tried to change the origin of the selection view of the logical database so I can have an extra field of BSID into 3 reports in the dynamic selection-screen. For two of them, the new field works fine and it is considerated into
-
How can a get my iMAC to recognize a newly installed optical drive?
I recently ordered a new Optical drive for my iMAC 12,1 to replace a damaged one. I followed the instructions online to replace the drive with no issues. I restarted the iMAC and it will not recognize the new optical drive. The optical drive won't ac