Solved

Reg Ex help

Posted on 2013-01-15
6
190 Views
Last Modified: 2013-01-15
Hi there,

need to pull some text out of hte following string:

{1:F01ABCDEFGHAXXX0000000000}{2:I101HSBFREDXXXXN}{4:|13||10|

Basically, I need to return the 8th character for a length of 11 whenever there is {2:

So for example:

from the above string i need to return HSBFREDXXXX
0
Comment
Question by:Wayne Atherton
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38777999
Depending on what language you are using, you might be able to use:

(?<=\{2:.{4}).{11}

Open in new window


...though, I honestly don't think you need a regex for this task.
0
 
LVL 1

Author Comment

by:Wayne Atherton
ID: 38778011
hi kaufmed,

I am using VBScript.

I need the regex, because the value isn't always in the same place, so i need to find it based on {2:
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38778069
because the value isn't always in the same place, so i need to find it based on {2:
Still don't think you need a regex  ; )

targetString = "{1:F01ABCDEFGHAXXX0000000000}{2:I101HSBFREDXXXXN}{4:|13||10|"
sentinel = "{2:"
startOf = InStr(targetString, sentinel)

If startOf > 0 Then
    toFind = Mid(targetString, startOf + 7, 11)
End If

MsgBox toFind

Open in new window

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:Wayne Atherton
ID: 38778130
i've put this into a Function, and pass the string and sentinal in as params, but it returns nothing

strIn = Objects("InputString").text
strTy = Objects("SearchString").text

 Function MTMessage(strIn,strTy)

    startOf = InStr(strIn, strTy)

    If startOf > 0 Then
    strTy = Mid(strIn, startOf + 7, 11)
    End If

 End Function
   Objects("OutputString").text = MTMessage(strIn,strTy)
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 38778237
You're not returning anything from the function.
0
 
LVL 1

Author Closing Comment

by:Wayne Atherton
ID: 38778483
cheers
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

789 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