Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular Expression

Posted on 2006-06-23
10
Medium Priority
?
427 Views
Last Modified: 2010-04-17
With the following regular expression what would be used to only select the carriage return at the end of the line...

A.{2}\r

In this scenario I would only want the \r selected but need to keep the beginning of the regular expression... not looking to find all carriage returns...



0
Comment
Question by:orionpm
  • 5
  • 4
10 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 16974133
Usually the $ says match end of line, so this has to be added and it should match the last return.

Regards
Friedrich
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 16975236
It's not clear what you;re trying to do, but if you're trying to grab the piece before the end of the line, you could try:

    \(A.{2}\)$

and the stuff between \( and \) will be called \1. Of course, there are slight variations in all these different regular expression interpreters - where are you using this?
0
 
LVL 1

Author Comment

by:orionpm
ID: 16975646
This is in VBScript...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:orionpm
ID: 16975838
For example out of the following string I would only want to select 't'... The string that I have could be alpha numberic, white space, etc which is why I am using the .{}.

A  t
B  z
A  t
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 16975847
For VBScript, assuming you want to grab the part of the expression from the "A" followed by 2 chars at the end of the line, you can use:

      myRegexp = new RegExp
      myRegexp.Pattern = "^(.*)(A.{2})$"
      myRegexp.Global = True
      myRegexp.IgnoreCase = True

      Dim found
      Set found = myRegexp.test(inputString)
         ' OK, we found the pattern ...
         ' RegExp.$1 contains the first part of the line, and RegExp.$2 contains the second part ("part" is the piece enclosed in parentheses)
      End If
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 16975854
OK - just saw your example. The Pattern field above should be set to:
    "^.*(..)$"

and RegExp.$1 will be equal to the last 2 chars in the line
0
 
LVL 1

Author Comment

by:orionpm
ID: 16975888
When I use the $ no results are returned... I am looking to only return the t in my regular expression as I want to replace the t only (but this criteria is based on matching on the first part of the string first; I wouldn't want to remove all t's in the data)... ie.

Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Pattern = "^(.*)(A.{2})$" 'Not sure at this point if I can select the t alone based on the first part of the string
objRegExp.Global = True
objRegExp.Multiline = True

strTEXT = objRegExp.Replace(strContents,"") 'At this point I would like the t only to be stored in objRegExp so that it can be removed
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 2000 total points
ID: 16975927
     myRegexp = new RegExp
      myRegexp.Pattern = "^.*(..)$" ' Pick up the last 2 characters
      myRegexp.Global = True
      myRegexp.IgnoreCase = True

      Dim found
      Set found = myRegexp.test(inputString)
      if  found
         strTEXT = RegExp.$1
      End If
0
 
LVL 1

Author Comment

by:orionpm
ID: 16976566
This is giving me an 'invalid character' on the .$1...
0
 
LVL 1

Author Comment

by:orionpm
ID: 16976645
Thanks for your assistance on this... I had to make a slight variation to .$1 for VBScript... This worked when I put this in quotes in my replace string...

strTEXT = objRegExp.Replace(strContents,"$1")
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Screencast - Getting to Know the Pipeline

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question