Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace pattern regexp

Status
Not open for further replies.

Dalie

Programmer
Feb 16, 2009
17
0
0
NL
I found a neat little script here @ tek-tips, but I don't fully understand the script. I know what it doest but don't know why. [ponder]
Code:
data = " 21"",""BOB D."",""StePH_hens"",""SA052"",""CALL REAL ESTATE"",""CALL01"",""(804)411-2222"" "
...
.Pattern = "\b(\w)(\w*?)\b"
...
Function ProperCase(match, submatch1, submatch2, index, source)
ProperCase = UCase(submatch1) & LCase(submatch2)
End Function
Source:
I echo'ed match, submatch1 etc. and know what it "holds" but where do they come from? Where are they declared? Basically what I want is to replace the .pattern with: [^a-z\d\u0100-\uffff] (so the script propercases after every special character, currently it fails at the _ in StePH_hens).

Explanation's are welcome and any help with replacing my .pattern with the current one is also very appreciated!
Dalie
 
Thanks! I read the articles and it's quite clear now! It also became quite clear my goal will be a bit of a struggle (as beginner) ;-)

So please take a look at my reasoning on resolving the problem:
1. I have a string i.e.: "the..___test i_the_ ##the"
2. I know how find all special characters. Use: [^a-z\d\u0100-\uffff])
3. The next step would be; uppercase the NEXT character. In case of a double special character (i.e. --)it would not cause any problem but it wouldn't be efficient. So I need to figure out how to find the first [A-Za-z] AFTER the occurrence of a character in the range of [^a-z\d\u0100-\uffff]
4. My first thoughts are two regexp. the first would temporarily "replace" all special characters by lets say "-" the second would find the first occurrence of [A-Za-z] and uppercase them.

Any suggestions for my "solution"?
 
I can't figure it out... :-( I still get to the point where I can't uppercase a character after a "_" (underscore)
Code:
strIn = "`a~a!a@a#a$a%a^a&a*a(a)a-a=a+a}a{a]a[a:a|a;a'a\a<a>a?a,a.a/a[b]_a[/b]"
...
strOut = "`A~A!A@A#A$A%A^A&A*A(A)A-A=A+A}A{A]A[A:A|A;A'A\A<A>A?A,A.A/A[b]_a[/b]"
...
.Pattern = "\b([a-z])"
Why?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top