How to build regular expression
I am trying to build a regular expression that will search the following array of strings for the sequence 3.1
Read Modem Information:
Device Type .......................... 2
Serial Number ........................ 11437
Primary Phone Number ................. 1800...
Secondary Phone Number ............... 1800...
Modem Software ....................... BOOT.3.1 Jun 17 2004 17:02:26
Bracelet Software .................... 4.0
Validation Number .................... Default
Login Name ........................... Default
Login Password ....................... Default
Case Number .......................... Default
Primary Encryption Key ............... Default
Secondary Encryption Key ............. Default
Dialing Format ....................... True
Call In Format ....................... True
Modem Download Flag is Clear ......... True
SCRAM Download Flag is Clear ......... True
SCRAM Char Table Load Flag is Clear .. True
Download Inhibit ..................... True
Exiting Boot (8 sec) ................. Switching to operating memory.
Main Revision ........................ SLCP.3.1 Jun 17 2004 17:02:46
Reset ................................ Complete
This is my first real foray into regular expressions and so I am lost trying to understand the help file.
Thanks!
Tay
Message Edited by slipstick on 09-25-2008 09:34 AM
I think the OP was puzzled about how to form a RE.
For the specific case or how to find the exact string "3.1", and to not match anything else, the RE is "3\.1"
Why?
For the most part, a RE search string is an exact character match. However things change when certain "special characters" are included in the search string. The RE help message says what they are, but the descriptions can be a bit daunting at first.
As a first example of special characters, the RE of "." (The single character fullstop) will match ANY single character. Thus a RE of "3.1" will match "3.1", "301", "3Z1", but not "31" or 3aa1".
Another special character is "*". It modifies the match to allow zero or more of the preceeding bit. So "3.*1" matches "3", followed by any number of any character (including no characters), followed by "1". so it will match "31", "301", "3ABC51", "31111111"
The action of a special character is cancelled by preceeding it with a backslash. So in the example above "3\.1" matches ONLY the string "3.1"
The best way to discover exactly how RE's work is to try some out. Make a VI containing Match Pattern, and suitable controls and indicators. Work through the examples and see how they operate. Now try your own!
Similar Messages
-
How to write regular expression to find desired string piece *duplicate*
Hi All,
Suppose that i have following string piece:
name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
ali
mehmetI use following statement
SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
2 select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
3 );
LST NM
name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
Any ideas about regexp?
Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
Regards...
Mennan
Edited by: mennan on Jul 4, 2010 9:53 PM
thread was posted twice due to chrome refresfment. Please ignore the thread and reply to How to write regular expression to find desired string pieceThe approach is to do cartesian join to a 'number' table returning number of records equal to number of names in the string.I have hardcoded 2 but you can use regexp_count to get the number of occurrences of the pattern in the string and then use level <=regexp_count(..... .
See below for the approach
with cte as(
select
'name:ali#lastname:kemal#name:mehmet#lastname:cemal' col ,level lev
from dual connect by level <=2)
select substr(regexp_substr('#'||col,'#name:\w+',1,lev),7)
from cte
/ -
How to find Regular Expressions in a Hash Map
Hi,
I Have a hash map with some keys. The Keys are like this(Java.util.regex, Javax.swing.table, javax.swing.text, Java.util.jar, Java.text etc). Suppose if the user gives the search pattern as "text", the o/p should be javax.swing.text and java.text.. How to do it using regular Expressions// Sample code...
import java.util.regex.*;
public class TestRegex {
public static void main(String[] args) {
String test1 = "java.util.regex";
String test2 = "javax.swing.text";
String test3 = "java.util.jar";
String test4 = "java.text";
Pattern pat = Pattern.compile(".*text.*");
Matcher mt1 = pat.matcher(test1);
System.out.println("1> " +mt1.matches());
Matcher mt2 = pat.matcher(test2);
System.out.println("2> " +mt2.matches());
Matcher mt3 = pat.matcher(test3);
System.out.println("3> " +mt3.matches());
Matcher mt4 = pat.matcher(test4);
System.out.println("4> " +mt4.matches());
} -
How to use regular expression to delete a character?
Hello,
I have a query,
select partition_name from dba_tab_partitions where table_owner='xxx'and num_rows <>0 and table_name = 'xxx';
P5
P6
P7
P12
P13
P14
P17
P18
P19
P20
P24
How can I use regular expression in above SQL query to get result without letter 'P', like..
5
6
7
12
13
14
17
18
19
20
24
thank youI find answer...
select regexp_replace(partition_name,'P','')
thanks anyway -
How to use regular expression to find string
hi,
who know how to get all digits from the string "Alerts 4520 ( 227550 ) ( 98 Available )" by regular expression, thanks
br, AndrewLiu,
You can use RegEx as
d+
Whether you are using CL_ABAP_REGEX class then
report zars.
data: regex type ref to cl_abap_regex,
matcher type ref to cl_abap_matcher,
match type c length 1.
create object regex exporting pattern = 'd+'
ignore_case = ''.
matcher = regex->create_matcher( text = 'Test123tes456' ).
match = matcher->match( ).
write match
You can find more details regarding REGEX and POSIX examples here
http://www.regular-expressions.info/tutorial.html
a® -
Hi,
I have a file that contains this format (separated by ;(semicolon) ):
user id;user name;email address;password;integer;list of integer(separated by ,(comma))
below is the example data :
abc;Abc;[email protected];password1;1;1,2
def;Def;[email protected];password;2;1,2,3
ghi;Ghi;[email protected];password;2;1
my question is how to verify the valid input for each row using regular expression..? TQ@Op. Doing a correct validation of e-mailaddresses
is very hard using regular expressions (doingbasic
validation is however easy)
http://www.regular-expressions.info/email.html
I like the RFC 822 compliant regexp :) -
How to use regular expressions to generate test data ?
Hi
Someone can help me on what I have to do in order to create test data with regular expressions ?
For example, I want to introduce a random telephone number (XXX-XXXX) in the phone number Form Field, I want to create the phone number using regular expressions in order to test different values in each playback of the script.
I don't want to use VB or vbscript in e-tester, I'm just trying to do this with e-load nav editor and e-load
Thanks a lotHi and thanks for your answer!, it's a great trick ^_^
I'm doing a research on how to improve the execution speed of the scripts in e-load, so actually I'm trying to avoid the use of databanks and VB code also.
I was expecting that maybe e-load, e-load nav editor or e-tester can automatically generate test data via Regular Expressions. Someone Knows if this is possible ?
Also can anyone tell me what the option "Automatically Generated (complex)" means ? I think that this will help me a lot
*you can find this option in e-load Nav Editor when you select a parameter in the tree view, then go to the "type" listbox in the properties pane, there you will find this option and some more options like :"Databanked variable", "Custom Dynamic Value", "Function".. etc.
Thanks again -
How to use regular expression replace for this special characters?
hi,
I need to replace the below string, but i couldnt able to do if we use the special charaters '+', '$' . can anyone suggest a way to do this?
select REGEXP_REPLACE('jan + feb 2008','jan + feb 2008', 'feb',1,0,'i') from dual
anwers should be :- febyou should use escape character \.
the regular expression will look like as follows:
select REGEXP_REPLACE('jan + feb 2008','jan \+ feb 2008', 'feb',1,0,'i') from dual
hope this is what you needed.
cheers,
Davide -
How to use regular expression in editor?
I tried to add some text to all line in selected text in editor
ie .
x:= x+1 ; change to x:=x+1; log_something;
y:= y-1; -> y:= y-1 ; log_something;
and so on.
Then
1. select some text in editor
2.pressed Ctrl-R
3.in "text to search for" I put "^\(.*\)$"
4.in "replace with" I put "\1 log_something;
5.check "Regular expressions"
6. check "Selected text only"
I got "The search text "^\(.*\)$" was not found."
What am I doing wrong?Thanks. But now editor wants to replace whole text, not only selected by me, regardless of <<check "Selected text only" >>
Update: if I pick "scope: all" instead of "prompted" it shows popup "text not found" but replaces text as requested.
Message was edited by: user4879976 -
How to add regular expression in viewobject bind variables
Hi,
Am using java class to set the adf bind variables
vm.setWhereClause("FIRST_NAME = :fname");
vm.defineNamedWhereClauseParam("fname", null, null);
vm.setNamedWhereClauseParam("fname","Alana");
It works fine and it returns Alana
But what i want is to set a regular expression where it returns all the names that are starting with A.
I tried with this.
vm.setNamedWhereClauseParam("fname","A*");
also
vm.setNamedWhereClauseParam("fname","A%");
but both didn work.
Please help.
Thanks,
HariPerfect... Thanks Arun.
I tried including last name too. i.e when either of the one matches (first name or last name)
vm.setWhereClause("upper(FIRST_NAME) LIKE upper(:fname||'%')");
vm.defineNamedWhereClauseParam("fname", null, null);
vm.setNamedWhereClauseParam("fname","A");
vm.setWhereClause("upper(LAST_NAME) LIKE upper(:lname||'%')");
vm.defineNamedWhereClauseParam("lname", null, null);
vm.setNamedWhereClauseParam("lname","A");
But i guess we should not give it like this as it doesnt seem to work.
Hari -
How to display regular expression text
I cannot seem to get the text of a regular expression to display in a text input. The regex is defined as:
Bindable]
private var myRegExp:RegExp=/^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$/;
In my form, I want to display the actual expression. The code I am using to do so is:
<mx:FormItem label="regExpLabel">
<mx:TextInput id="regExpTextInput" text="{myRegExp}" />
</mx:FormItem>
When I run the app, the data displayed in the regExpTextInput filed is /^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$/
What I want to display is only the regular expression, not including the slashes required by Flex at the beginning and end of the string. The data I want displayed is ^.*(?=.{10,32})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[.!@#$%*^&()+]).*$
I tried changing my variable type to String and leaving out the beginning and ending slashes, but that did not work either. Any thoughts?
Thanks!Hi, I am unable to understand your requirement properly but here is one demo of the using regular expression. In this application I am allowing only those character to be enter in the Textbox which are taken as the valid filename. Hope this will help you.
I think In your requirement first of all you have to take it as string type. And the second is that use \\ before every special character if you are writing it in the script. As I have done. Pls let me know if you
Have any issue with the code below.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
[Bindable]
private var regExpForFile : String
= "0-9A-Za-z\\&\\`\\~\\!\\@\\#\\$\\%\\^\\(\\)\\-\\_\\=\\+\\]\\}\[\\'\\;\\,\\.\\{ ";
]]>
</mx:Script>
<mx:VBox horizontalAlign="center" width="350">
<mx:Label text="Enter File Name"/>
<mx:TextInput id="fileName" width="170" height="20" restrict="{regExpForFile}"/>
</mx:VBox>
</mx:Application>
with Regards,
Shardul Singh Bartwal -
Finally I dont understand how to compound regular expressions, help please
I have read a lot of information about it, but .... I still do not understand how to make compound expresions ....
How must I use [ ] ?
Please three examples :
I want to search :
- any character but nothing of "abcd"
- any character but no 'dot' at any position
- any character but no 'dot' at position 4
Any good tutorial ?
Thank youThe way you have used the word 'search' create some uncertainty in my mind as to what you are asking for. I suspect that what you really want is a 'true' or 'false' that a given string matches some pattern. There are other ways to do this but ...
"any character but nothing of "abcd" " then use Matcher.matches() using regex "[^abcd]*" .
"any character but no 'dot' at any position" then Matcher.matches() using regex "[^.]*" .
"any character but no 'dot' at position 4" then Matcher.matches() using regex "(?!.{3}\\.)" .
Edited by: sabre150 on Aug 5, 2010 8:50 AM
Sodding forum markup! -
How to use regular expressions
Hey ,
I found my self getting troubled with using regex in java.
I know that in order to use regex, i need to import two classes
import java.util.regex.Matcher;
import java.util.regex.Pattern;
but I become entangled with the implementation.
I need to check if inserted string contains a number inside, so i build a pattern of regex. and compiled it. then i used matcher method. but from here all methods i use, i'm getting only the first digit of the number. ---> "sdasda25" i'm getting (after using group() ) only the digit 2.
is there any method that i can pass over all chars in the string (by loop) and to check if that particular char isMatch for my pattern (That's the way to implement it in C#, and i thought that here it will be the same...).
Tanxboth of you were right, I didnt write a '+' at the end of my pattern
thank you both -
How to write regular expression to find desired string piece
Hi All,
Suppose that i have following string piece:
name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
ali
mehmetI use following statement
SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
2 select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
3 );
LST NM
name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
Any ideas about regexp?
Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
Regards...
MennanHi, Mennan,
You can nest REGEXP_SUBSTR withing REGEXP_REPLACE to get the n-th occurrence, like this:
SELECT lst
, REGEXP_REPLACE ( REGEXP_SUBSTR ( lst
, 'name:[^#]*#lastname'
, 1
, n
, 'name:(.*)#lastname'
, '\1'
) AS nm If the pattern occurs fewer than n times, the expression above returns NULL. -
How to use regular expression using pattern and match concept for this scenario?
Hi Guys,
I have a string "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle"
I need to replace the numbers based on the below condition.
if more then 5, replace with many
if less then 5, replace with a few
if it is 1, replace with "only one"
below is my code, I am missing the equating part to replace the numbers could any one of you please help me out fixing this.
private static String REGEX="(\\d+)";
private static String INPUT="We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle";
//String pattern= "(.*)(\\d+)(.*)";
private static String REPLACE = "replace with many";
public static void main(String[] args) {
// Create a Pattern object
Pattern r = Pattern.compile(REGEX);
// Now create matcher object.
Matcher m = r.matcher(INPUT);
//replace the value 7 by the replace string
//How to equate the (\\d+) greater than a number and use it the below code.
INPUT = m.replaceAll(REPLACE);
//Print the final Result;
System.out.println(INPUT);
Thanks and Regards,Hi,
Try the following which makes use of "appendReplacement" instead with the "start" and "end" methods to locate and check the searched "regExp" string before dynamically setting the "replace" string:
String regExp = "\\d+";
String input = "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle";
String replace;
Pattern p = Pattern.compile(regExp);
// get a matcher object
Matcher m = p.matcher(input);
StringBuffer sb = new StringBuffer();
while (m.find()) {
Integer x = Integer.valueOf(input.substring(m.start(), m.end()));
replace = (x >= 5) ? "many" : (x == 1) ? "only one" : "few";
m.appendReplacement(sb, replace);
m.appendTail(sb);
System.out.println(sb.toString());
HTH.
Regards,
Rajen
P.S: Please mark the post as answered/helpful if it resolves your issue for the benefit of all community members.
Maybe you are looking for
-
I found a solution in one of Apple forums. I will copy her post: " I was checking the differences between my normal admin User account/Library/Application Support/Adobe/Lightroom contents and the one on the clean other admin User folder in the same
-
CR prompts for user credentials after refresh even though I'm using SSO
Hello Experts, We have a problem with a customeru2019s project concerning Crystal Reportu2019s Single Sign On feature: Even though weu2019re using SSO, Crystal Reports prompts for user credentials every time a refresh is performed manually in the bro
-
Java SE 6 required to run Flash CS6
But I have version 8, update 25 on my Mac running OS X Yosemite. If I install V6, will it overwrite my current version of Java? I'm not sure if this is a good idea. What about Flash CC 2014, what version of Java does it require? ~paul
-
Hello I am needing to create a form that will display database information and also go out to a windows shared location and read a JPG image back into the form. I creating a Rolladex of sorts. My question is I am total 100% new to forms I have never
-
Problem With Compatibil​ity Mode
My laptop runs Windows XP and I tried to change the compatibility settings so it would play a game made for WIndows 95. I went into the properties tab of the install file to make the changes and not only did the game not work but now I can't change t