I am trying to move away from TextPad and I just cant get reg expressions like ^ and $ to be replaced.
I have definitely ticked the regular expression box
What am I doing wrong
I am using this pattern and matching a string.
String s = "//name:value /name:value";
if (s.matches("(//?\\s*\\w+:\\w+\\s*)+")) {
// it fits
}
This works properly.
But if I want to have a string like "/name-or-address:value/name-or-address:value" which has this '-' in second part, it doesn't work.
I am using \w to match A-Za-z_, but how can I include - in that?
$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 :)
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
I want to run some commands using the system() command, I do this way:
execute_command_error("trash-put '/home/$filename'");
Where execute_command_error will report if there was an error with whatever system command it ran. I know I could just unlink the file using Perl commands, but I want to delete stuff using trash-put as it's a type of recycling program.
My problem is that $filename will sometimes have apostrophes, quotes, and other weird characters in it that mess up the system command or Perl itself.
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 trying to build a regular expression in javascript that checks for 3 word characters however 2 of them are are optional. So I have:
/^\w\w\w/i
what I am stumped on is how to make it that the user does not have to enter the last two letters but if they do they have to be letters
I have a bunch of strings which may of may not have random symbols and numbers in them. Some examples are:
contains(reserved[j])){
close();
i++){
letters[20]=word
I want to find any character that is NOT a letter, and replace it with a white space, so the above examples look like:
contains reserved j
close
i
letters word
What is the best way to do this?
I have a bunch of product sku's that look like:
abc234
asdf234324
adc234-b
result:
abc 234
asdf 234324
adc 234-b
I want to split the text at the first instance of a letter.
When I say split, basically I want to have access to both parts of the text, maybe in an array?
What's the best way to do this?
Well, there are other ways (hmmm... or rather working ways) to do it, but the question is why does this one fail?
/
\A # start of the string
( # group 1
(?: # group 2
[^()]* # something other than parentheses (greedy)
| # or
\( (?1) \) # parenthesized group 1
) # -group 2
+ # at least once (greedy)
) # -group 1
\Z # end of the string
/x
Fails to match a string with nested parentheses: "(())"
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 need a regular expression for some arguments that must match on a string.
here it is...
The string exists out of minimum 8 en maximum 20 characters.
These characters of this string may be characters of the alfabet or special chars
--With other words..all charachters except from the whitespaces
In the complete string there must be atleast 1 number.
The string cannot start with a number or an underscore
The last 2 characters of the string must be identical, But it doenst matter if those last --identical characters are capital or non-capital (case insensitive)
Must match all :
+234567899
a_1de*Gg
xy1Me*__
!41deF_hij2lMnopq3ss
C234567890123$^67800
*5555555
sDF564zer""
!!!!!!!!!4!!!!!!!!!!
abcdefghijklmnopq9ss
May not match :
Cannot be less then 8 or more then 20 chars:
a_1+Eff
B41def_hIJ2lmnopq3stt
Cannot contain a whitespace:
A_4 e*gg
b41def_Hij2l nopq3ss
Cannot start with a number or an underscore:
__1+Eff
841DEf_hij2lmnopq3stt
cannot end on 2 diffrent characters:
a_1+eFg
b41DEf_hij2lmnopq3st
Cannot be without a number in the string:
abCDefghijklmnopqrss
abcdef+++dF
!!!!!!!!!!!!!!!!!!!!
------------------------------------------------------
This is what I have so far...But I'm really breaking my head on this...
If you Don't know the answer completely it's not a problem...
I just want to get in the right direction
([^0-9_])(?=.*\d)(\S{8,20})(?i:[\S])\1
I'm getting an output data file of a program which looks like this, with more than one line for each time step:
0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00
7.9819E-06 1.7724E-02 2.3383E-02 3.0048E-02 3.8603E-02 4.9581E-02 5.6635E-02 4.9991E-02 3.9052E-02 3.0399E-02
....
I want to arrange it in ten columns
I have made a Python script, using regular expressions to delete \n in the proper lines, but I think that there should be a simpler more elegant way to do it, here is my script:
import re
with open('inputfile', encoding='utf-8') as file1:
datai=file1.read()
dataf=re.sub(r'(?P<nomb>( \d\.\d\d\d\dE.\d\d){8})\n','\g<nomb>',datai)
with open('result.txt',mode='w',encoding='utf-8') as resultfile:
resultfile.write(datof)
Thanks in advance
Hi,
What regular expressions do I need to extract section title(s) in a text file? So, in the following sample text, I'd like to extract
"Communication and Leadership"
"1.Self-Knowledge"
"2. Humility"
"(3) Clear Thinking".
Many thanks.
Communication and Leadership
True leaders understand that, rather
than forcing their followers into a
preconceived mold, their job is to
motivate and organize
followers to collectively accomplish
goals that are in everyone's
interests. The ability to communicate
this to co-workers and followers is
critical to the effectiveness of
leadership.
1.Self-Knowledge Superior leaders are able to devote their
skills and energies to leadership of a
group because they have worked through
personal issues to
the point where they know themselves
thoroughly. A high level of
self-knowledge is a prerequisite to
effective communication skills,
because
the things that you communicate as a
leader are coming from within.
2. Humility This subversion of personal preference requires a
certain level of humility. Although
popular definitions of leaders do not
always see
them as humble, the most effective
leaders actually are. This humility
may not be expressed in
self-effacement, but in a total
commitment to
the goals of the organization.
Humility requires an understanding of
one's own relative unimportance in
comparison to larger systems.
(3) Clear Thinking Clarity of thinking translates into clarity of
communication. A leader whose goals or
personal analysis is muddled will tend
to deliver
unclear or ambiguous directions to
followers, leading to confusion and
dissatisfaction. A leader with a clear
mind who is not ambivalent
about her purposes will communicate
what needs to be done in a
s traightforward and unmistakable
manner.
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.
Hey,
I'm using the code below to highlight some keywords in a text:
$message = str_ireplace($words,'<span class="hightlighted_text">'.$words.'</span>',$message);
The text may contain some html tags, for example , etc..
How can I highlight "normal" text, except the text between the html tags? Because when users search for "img" the text will be highlighted and the image doesn't work anymore.
<input type="text" value="[tabelas][something][oas]" id="allInput">
<script type="text/javascript">
allInput = document.getElementById('allInput');
var nivel = new Array('tabelas', 'produto');
for (var i =0; i < nivel.length ; i++ )
{
alert(" oi => " + allInput.value + " <-- " + nivel[i]) ;
var re = new RegExp("^\[" + nivel[i] + "\]\[.+\].+", "g");
alert(re);
allInput.value = allInput.value.replace(
re, "OLA");
alert(" oi 2 => " + allInput.value + " <-- " + nivel[i]) ;
}
</script>
Basically I whant to replace "something2 in the [tabelas][something][otherfield] by a number of quantity, I have been playing with regexp and had different results from this using .replace(/expression/,xxx ) and new RegExp() .
Best regards and thank you for any help.
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 of HTML stored in a database. Unfortunately it contains characters such as ®
I want to replace these characters by their HTML equivalent, either in the DB itself or using a Find Replace in my Python / Django code.
Any suggestions on how I can do this?
I am trying to match what is before /../ but after / with regular expressions, but i want it to look back and stop at the first / I feel like I am close but it just looks at the first slash and then takes everything after it like... input is this:
this/is/a/./path/that/../includes/face/./stuff/../hat
and my regular expression is
#\/(.*)\.\.\/#
matching
/is/a/./path/that/../includes/face/./stuff/../
instead of just
that/../ and stuff/../
how can i adapt what i'm doing to work?
I want to get all only youtube video ID from html code
look the (or multiple) object/embed code for youtube video
// html from database
<p>loremm ipsum dolor sit amet enot
<a href="link" attribute=""blah blah blah">anchor link</a>
</p>
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/Ou5eVl5eqtg&hl=es_ES&fs=1&"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/Ou5eVl5eqtg&hl=es_ES&fs=1&"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="425"
height="344">
</embed>
</object>
<image src="path/to/image.ext" >
<p>lorem ipsum dolor sit amet... blah</p>
<p>lorem ipsum dolor sit amet... blah</p>
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/Ou5eVl5eqtg&hl=es_ES&fs=1&"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/Ou5eVl5eqtg&hl=es_ES&fs=1&"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="425"
height="344">
</embed>
</object>
<p>blah</p>
blah<br/>
blah<br/>
blah<br/>
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?
I'm trying to put together a regular expression for a JavaScript command that accurately counts the number of words in a textarea.
One solution I had found is as follows:
document.querySelector("#wordcount").innerHTML = document.querySelector("#editor").value.split(/\b\w+\b/).length -1;
But this doesn't count any non-Latin characters (eg: Cyrillic, Hangul, etc); it skips over them completely.
Another one I put together:
document.querySelector("#wordcount").innerHTML = document.querySelector("#editor").value.split(/\s+/g).length -1;
But this doesn't count accurately unless the document ends in a space character. If a space character is appended to the value being counted it counts 1 word even with an empty document. Furthermore, if the document begins with a space character an extraneous word is counted.
Is there a regular expression I can put into this command that counts the words accurately, regardless of input method?