Removing whitespace only after closing tag in HAML - haml

I have a list of items separated by commas. It looks like this:
With a user-centric, iterative, and pragmatic approach
"User-centric" is wrapped in a span.highlight.
%span.highlight>user-centric removes the whitespace between the content and the comma as expected but it also removes the whitespace between 'a' and 'user-centric.'
With auser-centric, iterative . . .
What's the cleanest way to get rid of the trailing whitespace?

Related

How to write an XPath to select text with a quote & comma character?

How can I select a XPath that contains a text with both quote & comma character?
I have to find an element if the text contains =Yes, It's OK
My XPath does not save in ranorex tool even though if i put the text inside the double quotes like below
//span[text()="Yes, It's OK"]
So how can I save this xpath that uses "".in Ranorex
your use of double-quotes is correct. if
//span[text()="Yes, It's OK"]
doesn't match, it might be because the xpath engine has a lowercase bug (i have encountered PHP+DOMXPath+libxml2 systems where it would only match lowercase text even for text with uppercase characters, never quite figured out the problem there), or it might be because the text has hidden whitespace you're not aware of, maybe it actually has a hard-to-spot whitespace at the start or the end? anyway maybe contains() will work:
//span[contains(text(),"Yes, It's OK"]
or.. if it has the lowercase-issue i have encountered in the wild once before, maybe this will work:
//span[contains(text(),"yes, it's ok"]
(that really shouldn't be required, but i have been in that situation once before, and that was years ago, and that was... probably php5)

Filtering out substring from NSString . . .maybe using regex

Here is my problem:
I am trying to filter out html tags from an NSString object.
Most fixes for this simply remove everything falling between a < and a >, as well as those characters themselves. I am trying to figure out a way to remove the "< . . . >" substring ONLY if it does not contain white space or newline characters.
The way i was thikning about doing it looks something like this
while ([source rangeOfString#"someRegEx" options:NSRegularExpressionSearch].location != NSNotFound) {
//find the range of the substring
//check for newlines/whitespace characters
//replace occurrences of the string with "" if it doesn't have them
}
Firstly, does this seem like a good approach? Secondly, I'm having a lot of problems with figuring out what that regex would look like... does anyone have any ideas what it might look like?
This seems like a fine approach, provided the tags you're looking for really never contain whitespace, as m.buettner points out. The regex would look something like this:
<[^\s]*?>
The [^\s] is a negated character class which matches anything but whitespace characters. The ? makes the * lazy instead of greedy. So this regex in English means "Match a '<', then the smallest possible number of non-whitespace characters, then a '>'."
This is a helpful page.
Maybe you should consider employing an NSXMLParser, described here.
You get quite a rich set of delegate methods to extract whatever you like from the string.

Why does this space matter in this regular expression?

Why does the space make all the difference?
select * from beds where id~'.*Extra large.* (Red).*';
and
select * from beds where id~'.*Extra large.*(Red).*';
The first one returned nothing and the second acted as I wanted. An example of what I want matched is:
"Extra large" (Red) {2012 model}
I thought the first would work since there is a space after (Red)?
EDIT:Even if I escape the brackets with '\' I still can't have a space there.
The problem is that you have not escaped your brackets around "Red". Your regex should be:
'.*Extra large.* \(Red\).*'
This makes the brackets literal brackets, but without escaping them they create a regex group (and not characters to be matched).
Your first regex grouped the characters Red and required a space to precede that group Red, so it would match "... Red...", but there is a bracket in your input before Red, so it doesn't match.
Your second regex accepts any character(s) (via .*) before Red, so it matches.
This is because you're not escaping the ().
The brackets around "Red" create a group and are not included in the match. This
is the reason why the regexp without the whitespace works.
The .* in the regexp without the whitespace matches " (, then comes Red and after that ) {2012 model}. The brackets are matched by the .* operators.
The .* in the regexp with the whitespace matches " and the ( is not included in the pattern.
So the right pattern would be this:
.*Extra large.*\(Red\).*

How to exclude spaces when using ValidationExpression in vb.net

I want to exclude spaces when validating a textbox in vb.net.
Here is the current ValidationExpressopn value:
ValidationExpression="^([a-zA-Z0-9_-.\']+)#(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$" />
When user inputs space in textbox, I dont want that to render as error.
Example: I include spaces after "1#test.com "
This should not be treater as incorrect data in the textbox.
Any ideas?
If your spaces are leading or trailing you can do a Trim on the expressionToValidate before comparing to your regexp
Dim expressionWithoutTrailingAndLeadingWhiteSpaces As String = originalExpression.Trim()
If you want to modify the regExp to take into account the trailing spaces:
^[_a-z0-9-]+(.[a-z0-9-]+)#[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})( *)$
If you want to exclude also leading spaces add an extra ( *) at the beginning of the expression:
^( *)[_a-z0-9-]+(.[a-z0-9-]+)#[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})( *)$
Btw - the regExp you are providing is broken - I used the one found here (expression to validate email addresses)

Single-space regex replacement on Notepad++

I have a textfile of rows of values, each field delimited by a single space. The end of each row is signalled by the Windows-style {carriage return, newline}.
I would like to replace each spaces with a comma using Notepad++ but I am unfamiliar with whitespace regex on Notepad++.
Any help would be appreciated.
\s works for me at least as a whitespace token, just as it does in normal regular expressions. A single regular space character in the replace dialog works just as well.