Does anyone know of a regular expression for matching on a sequence of four numbers? I need a match on ascending (1234), descending (4321), or the same (1111).
Hi All,
I am trying to use jquery for validating forms.
This is the pattern that is allowed in a text box for a user.
var pattern = /^[a-zA-Z0-9!#$&%*+,-./: ;=?@_]/g;
If the user types anything else other than this then that has to be replaced with a "".
$(document).ready(function() {
$('#iBox').blur(function() {
var jVal = $('#iBox').val();
if(jVal.match(pattern)) {
alert("Valid");
} else {
alert("New "+jVal.replace(!(pattern),""));
}
});
});
});
But the replace function does not work this way.
I have a comma delimited list I want to import into a database, and in some cases the last item is blank:
item1, item2, item3
item1, item2,
item1, item2,
I'd like to replace all of these empty columns with a placeholder value using a regexp
item1, item2, item3
item1, item2, PLACEHOLDER
item1, item2, PLACEHOLDER
I tried preg_replace("/,\n/", ",PLACEHOLDER\n",$csv);, but this isn't working. Anyone know what regexp would work for this?
Hi,
This may be a silly question, but as someone relatively new to PHP, I'm wondering if there are any performance-related issues to frequently opening and closing PHP tags in HTML template code, and if so, what might be best practices in terms of working with php tags?
My question is not about the importance/correctness of closing tags, or about which type of code is more readable than another, but rather about how the document gets parsed/executed and what impact it might have on performance.
To illustrate, consider the following two extremes:
Mixing PHP and HTML tags:
<?php echo
'<tr>
<td>'.$variable1.'</td>
<td>'.$variable2.'</td>
<td>'.$variable3.'</td>
<td>'.$variable4.'</td>
<td>'.$variable5.'</td>
</tr>'
?>
// PHP tag opened once
Separating PHP and HTML tags:
<tr>
<td><?php echo $variable1 ?></td>
<td><?php echo $variable2 ?></td>
<td><?php echo $variable3 ?></td>
<td><?php echo $variable4 ?></td>
<td><?php echo $variable5 ?></td>
</tr>
// PHP tag opened five times
Would be interested in hearing some views on this, even if it's just to hear that it makes no difference.
Thanks.
Currently it takes about 3 minutes to run through a single 53 page word document. Hopefully you all have some advice about speeding up the process.
Code:
import win32com.client as win32
from glob import glob
import io
import re
from collections import namedtuple
from collections import defaultdict
import pprint
raw_files = glob('*.docx')
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = False
oFile = io.open("rawsort.txt", "w+", encoding = "utf-8")#text dump
doccat= list()
for f in raw_files:
word.Documents.Open(f)
doc = word.ActiveDocument #whichever document is active at the time
doc.ConvertNumbersToText()
print doc.Paragraphs.Count
for x in xrange(1, doc.Paragraphs.Count+1):#for loop to print through paragraphs
oText = doc.Paragraphs(x)
if not oText.Range.Tables.Count >0 :
results = re.match('(?P<number>(([1-3]*[A-D]*[0-9]*)(.[1-3]*[0-9])+))', oText.Range.Text)
stylematch = re.match('Heading \d', oText.Style.NameLocal)
if results!= None and oText.Style != None and stylematch != None:
doccat.append((oText.Style.NameLocal, oText.Range.Text[:len(results.group('number'))],oText.Range.Text[len(results.group('number')):]))
style = oText.Style.NameLocal
else:
if oText.Range.Font.Bold == True :
doccat.append(style, oText)
oFile.write(unicode(doccat))
oFile.close()
The for Paragraph loop obviously takes the most amount of time. Is there some way of identifying and appending it without going through every Paragraph?
Hi, new to python. This is probably simple but I haven't found an answer.
rndStr = "20101215"
rndStr2 = "20101216"
str = "Looking at dates between 20110316 and 20110317"
outstr = re.sub("(.+)([0-9]{8})(.+)([0-9]{8})",r'\1'+rndStr+r'\2'+rndStr2,str)
The output I'm looking for is:
Looking at dates between 20101215 and 20101216
But instead I get:
P101215101216
The values of the two rndStr's doesn't really matter. Assume its random or taken from user input (I put static vals here to keep it simple). Thanks for any help.
I am trying to extract text from a file between a '<' and a '', but only on a line starting with another specific pattern.
So in a file that looks like:
XXX Something here
XXX Something more here
XXX <\Lines like this are a problem
ZZZ something <\This is the text I need
XXX Don't need any of this
I would like to print only the "<\This is the text I need".
If I do
sed -n '/^ZZZ/p' FILENAME
it pulls the correct lines I need to look at, but obviously prints the whole line.
sed -n '/</,//p' FILENAME prints way too much.
I have looked into grouping and tried
sed -n '/^ZZZ/{/</,//} FILENAME but this doesn't seem to work at all.
Any suggestions? They will be much appreciated.
(Apologies for formatting, never posted on here before)
What i currently have is the following:
namespace AzureCCCMVC.Controllers
{
[Authorize(Roles="Admin")]
public class AdminController : Controller
{
//Stuff
}
}
what I want to do is have roles for each client such as
Roles { "DEMOAdmin", "GOOGAdmin" , "MSFTAdmin" }
and be able to Authorize The Client name (from URL) and in that role
I know I am doing a horrible job of explaining this... It is possible that I can have users that are users of several clients but only admin's of one ...
It appears that most modern languages and tools allow for extended regular expressions, and ERE looks a lot cleaner than BRE with all those backslashes. Are there any major drawbacks in compatibility or maintainability when using ERE instead of BRE?
Hi,
I have the following JSON object which has a date field in the following format:
{
"AlertDate": "\/Date(1277334000000+0100)\/",
"Progress": 1,
"ReviewPeriod": 12
}
I want to write a regular expression or a function to convert it to a javascript object so that it is in the form:
{
"AlertDate": "AlertDate":new Date(1277334000000),
"Progress": 1,
"ReviewPeriod": 12
}
The above date format fails validation in the JQuery parseJSON method.
I would like to convert the 1277334000000+0100 into the correct number of milliseconds to create the correct date when eval is called after validation.
Can anyone help me out with a good approach to solving this?
Cheers
Paul
$w = 'self-powering';
%h = (self => 'self',
power => 'pau?',
);
if ($w =~ /(\w+)-(\w+)ing$/ && $1~~%h && $2~~%h && $h{$2}=~/?$/) {
$p = $h{$1}.$h{$2}.'ri?';
print "$w:"," [","$p","] ";
}
I expect the output to be
self-powering: selfpau?ri?
But what I get is:
self-powering: [ri?]
My guess is something's wrong with the code
$h{$2}=~/?$/
It seems that when I use
$h{$2}!~/?$/
Perl will do what I mean but why I can't get "self-powering: selfpau?ri?"?
What am I doing wrong? Any ideas?
Thanks as always for any comments/suggestions/pointers :)
Simple example: we have string "Some sample string Of Text". And I want to filter out all stop words (i.e. "some" and "of") but I don't want to change letter case of other words which should be retained.
If letter case was unimportant I would do this:
str.toLowerCase().replaceAll ("a|the|of|some|any", "");
Is there an "ignore case" solution with regular expressions in java?
I've inherited some C# code that contains about a thousand lines of source that I need to modify, transforming it from this:
newDataRow["to_dir"] = comboBox108.Text;
To this:
assetAttributes.Add("to_dir", comboBox108.Text);
The lines occur in various places throughout the application in groups of 40 or 50. Modifying each line by hand in Visual Studio 2008 can be done but it's labor intensive and prone to errors.
Is there a Windows utility out there that will let me cut and paste groups of code into it and then run some sort of reg-ex expression to transform the individual lines one-by-one? I'd also be willing to use some sort of VS 2008 add-in that performed the same set of reg-ex operations against a selection of code.
Thanks in advance.
lines = "some stuff\"some other \"stuff\"\"";
lines = lines.Replace("\"", "\"");
lines = lines.Replace("\"", "\"");
in its current context and in its simplest form these two actions seem absolutely pointless but when I put this into code it will be not be pointless and will have a purpose other than replacing itself with itself.
OK so I have the String lines that has 4 escaped quotation marks and I wish to replace the first quote with a quote and the end quote with a quote how would I accomplish this without replacing any of the inner quotes?
Hi,
This is the preg_match i am trying to use to find specific text in text file.
if (preg_match($regexp,$textFile,$result) > 0) {
echo "Found ".$result[0];
} else {
echo "Not found";
}
However, the result is always Found and nothing more. The result array is empty. Now i read that preg_match can't work with long strings.
My text file is about 300KB so thats 300000 characters i guess.
I am 100% sure that the searched string is in the text file, and the fact that preg_match function returns value above 0 means it found it, but it didn't place it into the result array somehow.
So my question would be, how do i make it work?
regexp would be /[specific text]\{(\d*)\}/ so, of course i want to be able to get the number in the parentheses.
Hi
How can I extract the longest of groups which start the same way
For example, from a given string, I want to extract the longest match to either CS or CSI.
I tried this "(CS|CSI).*" and it it will return CS rather than CSI even if CSI is available.
If I do "(CSI|CS).*" then I do get CSI if it's a match, so I gues the solution is to always place the shorter of the overlaping groups after the longer one.
Is there a clearer way to express this with re's? somehow it feels confusing that the result depends on the order you link the groups.
Hi All
I'm trying to extract/match data from a string using regular expression but I don't seem to get it.
I wan't to extract the highlighted characters from the following string:
/xubuntu/daily/current/lucid-alternate-**i386**.iso
This should also work in case of:
/xubuntu/daily/current/lucid-alternate-**amd64**.iso
Thanks a lot for your help.
I have a string which contains a contiguous chunk of digits and then a contiguous chunk of characters. I need to split them into two parts (one integer part, and one string).
I tried using String.split("\D", 1), but it is eating up first character.
I checked all the String API and didn't find a suitable method.
Is there any method for doing this thing?
I figured out that in order to turn [some name] into [some_name] I need to use the following expression:
s/\(\[[^ ]*\) /\1_/
i.e. create a backreference capture for anything that starts with a literal '[' that contains any number of non space characters, followed by a space, to be replaced with the non space characters followed by an underscore. What I don't know yet though is how to alter this expression so it works for ALL underscores within the braces e.g. [a few words] into [a_few_words].
I sense that I'm close, but am just missing a chunk of knowledge that will unlock the key to making this thing work an infinite number of times within the constraints of the first set of []s contained in a line (of SQL Server DDL in this case).
Any suggestions gratefully received....
I'm trying to match the point between 2nd and 3rd paragraphs to insert some content. Paragraphs are delimited either by <p> or 2 newlines, mixed. Here's an example:
text text text text
text text text text
<p>
text text text text
text text text text
</p>
<--------------------------- want to insert text here
<p>
text text text text
text text text text
</p>
I am using jquery-ui tabs and dialog functionality.
Each tab has a button on the page which opens a dialog. This works for one of the tabs. However if I go the second tab, the button does not work there. When I come back to the first tab, the dialog does show up but the problem is I notice as I make switches back and forth to the first tab, it keeps on inserting new div's while the old div's have display:none set on them.
I am doing this using JSP. This is how the reusable jsp looks like:
<script>
$(function() {
var formData = null;
$.ajax({
url : "addFormGenerator.html",
success : function(data) {
formData = data;
$("#addFormDialog").html(data);
$("#addFormDialog").dialog({
autoOpen : false,
height : 300,
width : 350,
modal : true,
buttons : {
"Add" : function() {
$(this).dialog("close");
},
Cancel : function() {
$(this).dialog("close");
}
},
close : function() {
}
});
}
});
$("#addButton").button().click(function() {
$("#addFormDialog").html(formData);
$("#addFormDialog").dialog("open");
});
});
</script>
<button id="addButton">Click here to Add New</button>
<div id="addFormDialog" title="Add New"></div>
This jsp fragment is included in other jsp pages as well.
I was assuming as I switch between tabs the old button will be garbage collected.
Can you help me understand the problem and fix it?
So I am trying to read an XML file into a string in Perl and send it as part of a SOAP message. I know this is not ideal as there are methods for SOAP sending files, however, I am limited to having to use the SOAP that is set up, and it is not set up for sending with file support.
Therefore I need to parse out the markup tags < and replace them with []. What is the best way to do this?
Hi all,
I have written this piece of code that splits a string and stores it in a string array:-
String[] sSentence = sResult.split("[a-z]\.\s+");
However, I've added the [a-z] because I wanted to deal with some of the abbreviation problem. But then my result shows up as so:-
Furthermore when Everett tried to instruct them in basic mathematics they proved unresponsiv
I see that I loose the pattern specified in the split function. Its okay for me to loose the period, but loosing the last letter of the word disturbs its meaning.
Could some one help me with this and in addition also could someone help me with dealing with abbreviations? Like because I split the string based on periods, I do not want to loose the abbreviations.
Thanks in advance