2 Regex challenges

Results 1 to 2 of 2

Thread: 2 Regex challenges

  1. #1
    Join Date
    Dec 1969

    Default 2 Regex challenges

    Greetings All, <BR>Im doing my best to learn how to use regular expressions but am runing into walls here. <BR>Could someone help me out. I have 2 challenges to beat. <BR>1. I need to replace all @@sometext@@ with its ajoining merge item. This is going to be used to merge a template. <BR>for example: <BR><BR>Dear @@name@@, <BR>How are you, blah blah @@moreblah@@ <BR>..... <BR>.....<BR> would become <BR><BR>Dear John, <BR>How are you, Blah Blah some other stuff <BR>...... <BR>.....<BR><BR>2. the secound challenge is that I need to grab the domain from the url but without the begining or ending. <BR>for example. <BR><BR><BR>www.Domain.com = Domain <BR>Domain.com = Domain <BR>something.Domain.com = Domain <BR>+ it may not be a .com, any of the domain ending applys. <BR><BR><BR>Can someone help me on this? <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: 2 Regex challenges

    &nbsp;<BR>1. The text you want to replace is predetermined and doesn&#039;t vary, so a simple application of the replace function would suffice:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;Replace(my Text,"@@name@@",myName)<BR><BR>2. Try this,<BR><BR>regEx.Pattern = "http://(www.)?([-.w]+).[a-z]{2,3}/"<BR>regEx.Global = False<BR>regEx.IgnoreCase = True <BR>Set Matches = regEx.Execute(strUrl)<BR>If Matches.Count = 1 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;Set match = Matches(0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;strDomainNam e = Match.SubMatches(1)<BR>End If<BR><BR>** The above assumes that the domain extension contain letters and is 2-3 characters long. For a domain extension such as "co.uk", "co" will be included as part of the string you want, which is incorrect. The way around this is to use alternation to check each possible domain extension:<BR><BR>regEx.Pattern = "http://(www.)?([-.w]+).(com&#124net&#124org&#124co.uk)/"<BR><BR>** Place the most common extensions first<BR><BR>You get the picture... Visit register.com to get more domain extensions.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts