I'd like to know what to put in textpad's syntax file to fix the issue where, say, in an html file, you're writing a paragraph and an apostrophe creates syntax highlighting until the next aspostrophe.
Ex:
<p>Hi, I'm an example.
lol text here placeholder lorem ipsum I've died.</p>
I've placed in bold what would be color highlighted in textpad, for lack of stackoverflow coloring knowledge. :P It would be seen as similar to <a href='http://string.lol'> where you would normally use a pair of apostrophes or quotes. I realize that the issue may be in the way the syntax file is set up, where it's matching for any apostrophe instead of matching for an apostrophe not separated by a space. Ideally it would also need to match for equal signs and other common characters that would be seen directly next to an apostrophe or quote.
Here's where I believe it could be found inside the syntax file:
[Syntax]
Namespace1 = 6
IgnoreCase = No
InitKeyWordChars = A-Za-z_
KeyWordChars = A-Za-z0-9_
OperatorChars = -+*/!~%^&|=#`.,;:
KeyWordLength =
BracketChars = {[()]}
PreprocStart = #
HexPrefix = 0x
SyntaxStart =
SyntaxEnd =
CommentStart = /*
CommentEnd = */
CommentStartAlt = <!--
CommentEndAlt = -->
SingleComment = //
SingleCommentCol =
SingleCommentAlt =
SingleCommentColAlt =
SingleCommentEsc =
StringsSpanLines = Yes
StringStart = "
StringEnd = "
StringAlt = '
StringEsc = \
CharStart = '
CharEnd = '
CharEsc = \
You have your String options at the bottom, but is textpad capable of accepting some kind of expression matching or regex, and if so, how would I best do this? I've looked on google and here, and the keywords are just too vague to find anything that does exist on the topic, if anything does.
Thank you for any help you can provide.
I fixed this problem by editing the line in perl5.syn that reads
StringAlt = '
to instead be
; StringAlt = '
(the leading semi-colon comments out the StringAlt setting on that line; or you could just delete that line outright).
You need to use
SyntaxStart = <
SyntaxEnd = >
This will restrict syntax highlighting to only be within tags, and it's the best you can do with TextPad.
Related
How do I use .js to regex out the quotation marks in the following string?
var wtfx = "<div>ExternalClass=5"</div>44FB";
var wtf = /<div>ExternalClass.*>/;
wtf = wtfx.replace(wtf, "");
alert(wtf);
shows this does not work. If I take the '"' out then it does. How do I 'escape' the quote?
for example I'd like to use reg ex on the above wtf string to yield only the string 44FB.
not getting this.
The following Code will alert "44FB":
var wtfx = "<div>ExternalClass=5\"</div>44FB";
var wtf = /<div>ExternalClass.*>/;
wtf = wtfx.replace(wtf, "");
alert(wtf);
The only change is the Backslash before the Quotationmark in line 1.
However, I'm not 100% sure if that is what you want. Feel free to write a comment if you need another result.
I want to write a regex in Ruby that will add a backslash prior to any open square brackets.
str = "my.name[0].hello.line[2]"
out = str.gsub(/\[/,"\\[")
# desired out = "my.name\[0].hello.line\[2]"
I've tried multiple combinations of backslashes in the substitution string and can't get it to leave a single backslash.
You don't need a regular expression here.
str = "my.name[0].hello.line[2]"
puts str.gsub('[', '\[')
# my.name\[0].hello.line\[2]
I tried your code and it worked correct:
str = "my.name[0].hello.line[2]"
out = str.gsub(/\[/,"\\[")
puts out #my.name\[0].hello.line\[2]
If you replace putswith p you get the inspect-version of the string:
p out #"my.name\\[0].hello.line\\[2]"
Please see the " and the masked \. Maybe you saw this result.
As Daniel already answered: You can also define the string with ' and don't need to mask the values.
I'm trying to reformat German dates (e.g. 13.03.2011 to 2011-03-13).
This is my code:
str = "13.03.2011\n14:30\n\nHannover Scorpions\n\nDEG Metro Stars\n60\n2 - 3\n\n\n\n13.03.2011\n14:30\n\nThomas Sabo Ice Tigers\n\nKrefeld Pinguine\n60\n2 - 3\n\n\n\n"
str = str.gsub("/(\d{2}).(\d{2}).(\d{4})/", "/$3-$2-$1/")
I get the same output like input. I also tried my code with and without leading and ending slashes, but I don't see a difference. Any hints?
I tried to store my regex'es in variables like find = /(\d{2}).(\d{2}).(\d{4})/ and replace = /$3-$2-$1/, so my code looked like this:
str = "13.03.2011\n14:30\n\nHannover Scorpions\n\nDEG Metro Stars\n60\n2 - 3\n\n\n\n13.03.2011\n14:30\n\nThomas Sabo Ice Tigers\n\nKrefeld Pinguine\n60\n2 - 3\n\n\n\n"
find = /(\d{2}).(\d{2}).(\d{4})/
replace = /$3-$2-$1/
str = str.gsub(find, replace)
TypeError: no implicit conversion of Regexp into String
from (irb):4:in `gsub'
Any suggestions for this problem?
First mistake is the regex delimiter. You do not need place the regex as string. Just place it inside a delimiter like //
Second mistake, you are using captured groups as $1. Replace those as \\1
str = str.gsub(/(\d{2})\.(\d{2})\.(\d{4})/, "\\3-\\2-\\1")
Also, notice I have escaped the . character with \., because in regex . means any character except \n
I want to replace a particular value followed by TRN* to some other value.How to do the coding for the same?..Please provide an example.
For example :
TRN*12345*34444~
This is a segment in my file(like this I have many TRN* segments in my file).I want to replace the segment after TRN* and before next * (ie.12345)with some other value.
Is there any way to do this by using vbscript?
Thanks in advance
The regular expression way of safetyOtter is the way to go, you only have to fiddle with the pattern and replacement string:
originalString = "TRN*12345*34444~"
replaceValue = "78910"
Set re = new RegExp
re.Pattern = "(.*TRN\*)([^*]+)(.*)"
re.IgnoreCase = False
' This keeps the first and last part between parenthesis, but replaces the middle part
newString = re.Replace(originalString, "$1" & replaceValue & "$3")
msgbox newString
' result: TRN*78910*34444~
Something like this should work, may have to tweak, can't test it at the moment
Set regEx = New RegExp
regEx.Pattern = "TRN\*.*?\*"
regEx.IgnoreCase = True
replStr = "TRN*" & SomeOtherValue& "*"
ReplaceTest = regEx.Replace(YourStringHere, replStr)
Edit:
if you are looking to replace a specific number with another, a simple:
YourStringHere = Replace(YourStringHere,"TRN*12345*","TRN*67890*")
Is enough
I have 6400+ records which I am looping through. For each of these: I check that the address is valid by testing it against something similar to what the Post Office uses (find address). I need to double check that the postcode I have pulled back matches.
The only problem is that the postcode may have been inputted in a number of different formats for example:
OP6 6YH
OP66YH
OP6 6YH.
If Replace(strPostcode," ","") = Replace(xmlAddress.selectSingleNode("//postcode").text," ","") Then
I want to remove all spaces from the string. If I do the Replace above, it removes the space for the first example but leave one for the third.
I know that I can remove these using a loop statement, but believe this will make the script run really slow as it will have to loop through 6400+ records to remove the spaces.
Is there another way?
I didn't realise you had to add -1 to remove all spaces
Replace(strPostcode," ","",1,-1)
Personally I've just done a loop like this:
Dim sLast
Do
sLast = strPostcode
strPostcode = Replace(strPostcode, " ", "")
If sLast = strPostcode Then Exit Do
Loop
However you may want to use a regular expression replace instead:
Dim re : Set re = New RegExp
re.Global = True
re.Pattern = " +" ' Match one or more spaces
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("O P 6 6 Y H.", "")
Set re = Nothing
The output of the latter is:
D:\Development>cscript replace.vbs
OP66YH.
OP66YH.
OP66YH.
D:\Development>
This is the syntax Replace(expression, find, replacewith[, start[, count[, compare]]])
it will default to -1 for count and 1 for start. May be some dll is corrupt changing the defaults of Replace function.
String.Join("", YourString.Split({" "}, StringSplitOptions.RemoveEmptyEntries))
Because you get all strings without spaces and you join them with separator "".