My Regex:
#\<param name\=\"src\"+.+\"\s\/\>#
The problem is that stops at the second /> but I want just the first <param>.
<param name="example" src="hello.swf" />
<param name="stuff2" />
So how should I get just the first param?
Probably something like this...
#param name="([a-zA-Z0-9]+)" src="(.*?)"#is
Your result should be in $match[2]
Related
I was trying to use the package pid (http://wiki.ros.org/pid) to control the stability of a drone (Parrot AR drone 2.0).
I created a launch that use one controller for each axis (x,y and z):
<node name="controller" pkg="pid" type="controller" ns="pid_x" output="screen" >
<param name="node_name" value="pid_x" />
<param name="Kp" value="-0.0887" />
<param name="Ki" value="0.0" /> <!-- Arranca en cero pero es 0.16597 -->
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/setpoint_x" />
<remap from="state" to="/ardrone/odometry/pose/pose/position/x" />
<remap from="/pid_x/control_effort" to="/publicador_intermedio_x" />
</node>
<node name="controller" pkg="pid" type="controller" ns="pid_y" output="screen" >
<param name="node_name" value="pid_y" />
<param name="Kp" value="0.0763" />
<param name="Ki" value="0.0" /> <!-- Arranca en cero pero es 0.11037 -->
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/pid_y/setpoint_y" />
<remap from="state" to="/pid_y/state" />
<remap from="/pid_y/control_effort" to="/publicador_intermedio_y" />
</node>
<node name="controller" pkg="pid" type="controller" ns="pid_z" output="screen" >
<param name="node_name" value="pid_z" />
<param name="Kp" value="0.9827" />
<param name="Ki" value="0.0" />
<param name="Kd" value="0.0" />
<param name="max_loop_frequency" value="105.0" />
<param name="min_loop_frequency" value="95.0" />
<remap from="setpoint" to="/setpoint_z" />
<remap from="state" to="/ardrone/odometry/pose/pose/position/z" />
<remap from="/pid_z/control_effort" to="/publicador_intermedio_z" />
</node>
</launch>
I was just checking how it works using just the second controller, so please don't mind the other ones. The state takes information from the topic pid_y/state that reads the /ardrone/odometry/pose/pose/position and publishes the value of y (if u want to see the node I can post it). Then, pid_controller is publishing in /publicador_intermedio_x that it's a node that works like a conection betweeen the outcome of the controller and the topic /cdm_vel of the drone (i mean, the topic where you need to publish in order to controlling the drone). Finally the last one is the big problem: setpoint. In the pid package we can find an example in order to understand how it works. So I copied the node that publishes the setpoint values in order to make a test. It looks like this:
#include <ros/ros.h>
#include <std_msgs/Float64.h>
int main(int argc, char** argv)
{
//inicio comunicacion con sistema ROS
ros::init(argc, argv, "publicador");
ROS_INFO("Starting setpoint publisher");
ros::NodeHandle nh;
while (ros::ok() && ros::Time(0) == ros::Time::now())
{
ROS_INFO("Setpoint_node spinning, waiting for time to become non-zero");
sleep(1);
}
std_msgs::Float64 contador;
contador.data = 1.0;
//creamos un objeto publicador
ros::Publisher pub = nh.advertise<std_msgs::Float64>("/pid_y/setpoint_y", 1000);
ros::Rate loop_rate(10); // acomodar a frecuencia que no sature, pero q sea mas rapida que publicacion odometria
while (ros::ok())
{
ros::spinOnce();
pub.publish(contador);
contador.data = contador.data + 1;
pub.publish(contador);
ROS_INFO("Valor publicado: [%f]", contador);
loop_rate.sleep(); //duermo hasta proxima iteracion
}
Now that I already explained the code, this is what isn’t working: I run the pid with the nodes that it needs. The launch reads correctly the setpoint and the state (the odometry) but it doesn't publish because:
prev_time is 0, doing nothing
If i understood the code correctly, It’s because prev time uses the time between two consecutive values to calculate the error. That's ok. But when the launch must to read the second setpoint value it never does it. It stays in
Waiting first setpoint value
and never read it, even when the node is publishing the new value. I can't understand what I'm doing wrong.
Can anyone help me?
hy guys,
i'm trying to replace a part of string inside a property like below
<property file="build-local.properties" /> <--
<propertyregex property="destProperty" input="${sourceProperty}" regexp="${whatMatch}" replace="" global="true" />
in order to replace content of property ${sourceProperty} matching string ${whatMatch} replacing with none (in this case) and finally assign result to property ${destProperty}
Currently i'm getting ${whatMatch} from build-local.properties file and ${sourceProperty} as terminal arguments
But it doesn't work.
Where i'm wrong ??
Important notes
Changing
<propertyregex property="destProperty" input="${sourceProperty}" regexp="${whatMatch}" replace="" global="true" />
from above to
<propertyregex property="destProperty" input="${sourceProperty}" regexp="HARDCODED_STRING" replace="" global="true" />
Thanks in advance
we solved using the following format:
<propertyregex property="normalizedAppVersion" input="${appVersion}" regexp="${projectPrefix}\." replace="" casesensitive="false" />
IMPORTANTS NOTES
If you're trying to replace a text that contains a ".", you can have some problem specifying dot inside property definition. So i just using the "."
# instead "MYPACKAGE."
projectPrefix="MYPACKAGE."
regexp="${projectPrefix}\."
directly in the regexp attribute value. I don't know why but if not doesn't work for me.
Thanks BTW
I posted a simplified version of this question before, but I think I might have simplified it too much, so here is the actual problem.
I want to use regex (in Notepad++ or similar) to find "a_dog" in the following (sorry about the wall):
<object classid="clsid:D27CDB6E-AE6D-11cf" id="FlashID">
<param name="movie" value="../flash/words/a_dog.swf">
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="6.0.65.0">
<!--[if !IE]>-->
<object data="../flash/words/a_dog.swf" type="application/x-shockwave-flash">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="6.0.65.0">
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
Then I want to use a back-reference to replace all instances of øø with a_dog in the following:
<input type="button" class="ButtonNormal" onClick="audio_func_øø()">
<script>
function audio_func_øø() {
var playAudio = document.getElementById("element_øø");
playAudio.play();
}
</script>
<audio id="element_øø">
<source src="../audio/words/øø.mp3" type='audio/mpeg'>
<source src="../audio/words/øø.wav" type='audio/wav'>
</audio>
So that only the second code is left (with a_dog instead of øø), and no trace of the first code remains.
I don't know how to do this in Notepad++, but you can do this in SublimeText using regex, snippets, and multiple selection:
First make a new snippet (guide) with the following in it:
<snippet>
<content><![CDATA[
<input type="button" class="ButtonNormal" onClick="audio_func_$1()">
<script>
function audio_func_$2() {
var playAudio = document.getElementById("element_$3");
playAudio.play();
}
</script>
<audio id="element_$4">
<source src="../audio/words/$5.mp3" type='audio/mpeg'>
<source src="../audio/words/$6.wav" type='audio/wav'>
</audio>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>audioSnippet</tabTrigger>
</snippet>
Save it as whatever you like in your User package. Follow the linked article if you have any questions on how/where to save it to get it working. I will discuss how this works later on.
Next use the following regex in Sublime Text by searching (with regex enabled) using the following pattern:
(?<=value="../flash/words/).+(?=\.swf)
And hit "Find All" - this will select all the names (e.g. 'a_dog', 'a_cat', 'a_plane') using multiple selection.
Copy the selected words (Ctrl+C or equivalent on your system)
In the menu, Selection->Expand to Paragraph (This will select where the <object> begins, to where </object> ends)
Hit Delete/Backspace to remove the <object>'s
Type in your snippet shortcut (above I've defined it to be "audioSnippet") and hit Tab
Paste in your copied text (Ctrl+V or equivalent on your system)
You will notice that you have only replaced the text in the snippet where the $1 appears. you will need to hit Tab to jump to $2, paste the text again (Ctrl+V), and repeat until you get to tab stop $6.
I've made a screen capture that you can look at here: http://youtu.be/oo2MQV3X244 (unlisted video on YouTube)
I have in hithighlightedsummary the tag this
<ddd /> Posted: 2/8/2011 10:04 PM <ddd /> Subject: some subject <ddd /> Some Text <ddd />
I would like to get the 'some subject' as a sub string. I have tried using "substring-after(hithighlightedsummary, 'Subject:')", But I don't know how to combine that with the <ddd /> tag.
Did you mean something like this?
substring-after(
//hithighlightedsummary
/text()[
contains(.,'Subject:')
],
'Subject:'
)
Note: I've used an absolute expression because you didn't provide information about context.
Edit2: only regex match solutions, please. thank you!
Edit: I'm looking for regex solution, if it's exist. I have other blocks with the same data that are not XML, and I can't use Perl, I added Perl tag as I'm more familiar with regexes in Perl. Thanks in advance!
I Have list like this:
<Param name="Application #" value="1">
<Param name="app_id" value="32767" />
<Param name="app_name" value="App01" />
<Param name="app_version" value="1.0.0" />
<Param name="app_priority" value="1" />
</Param>
<Param name="Application #" value="2">
<Param name="app_id" value="3221" />
<Param name="app_name" value="App02" />
<Param name="app_version" value="1.0.0" />
<Param name="app_priority" value="5" />
</Param>
<Param name="Application #" value="3">
<Param name="app_id" value="32" />
<Param name="app_name" value="App03" />
<Param name="app_version" value="1.0.0" />
<Param name="app_priority" value="2" />
</Param>
How can I get a block for one app if I only know, say, a value of app_name. For example for App02 I want to get
<Param name="Application #" value="2">
<Param name="app_id" value="3221" />
<Param name="app_name" value="App02" />
<Param name="app_version" value="1.0.0" />
<Param name="app_priority" value="5" />
</Param>
Is it possible to get it, if other "name=" lines are not known (but there's always name="app_name" and Param name="Application #")?
Can it be done in a single regex match? (doesn't have to be, but feels like there's probably a way).
since your content seems to be some XML why don't use a real parser to do the task ?
use XML::XPath;
use XML::XPath::XMLParser;
my $xp = XML::XPath->new(filename => 'test.xhtml');
my $nodeset = $xp->find('/Param[#name=\'Application #\']'); # find all applications
foreach my $node ($nodeset->get_nodelist) {
print "FOUND\n\n",
XML::XPath::XMLParser::as_string($node),
"\n\n";
}
you can read a bit more about XPath here and have full reference at the w3c.
I advise you not to use reg exp to do that task because it's going to be complicate and not maintenable.
note: also possible to use the DOM API just depend the one you like the most.
This seems to be a sad case of bogus XML. A misguided attempt to create enterprisey software at best. The developers could have used a sane configuration file format such as:
[App03]
app_id = 32767
app_version = 1.0.0
...
but they decided to drive everyone insane with meaningless BSXML.
I would say, if this file is less than 10 MB in size, just go ahead and use XML::Simple. If the file indeed consists of nothing but repeated blocks of exactly what you posted, you can use the following solution:
#!/usr/bin/perl
use strict; use warnings;
my %apps;
{
local $/ = "</Param>\n";
while ( my $block = <DATA> ) {
last unless $block =~ /\S/;
my %appinfo = ($block =~ /name="([^"]+?)"\s+value="([^"]+?)"/g);
$apps{ $appinfo{app_name} } = \%appinfo;
}
}
use Data::Dumper;
print Dumper $apps{App03};
Edit: If you cannot use Perl and you won't tell us what you can use, there is not much I can do but point out that
/name="([^"]+?)"\s+value="([^"]+?)"/g
will give you all name-value pairs.
I would prefer a parser solution, too. If you absolutely have to use a regex and understand all the disadvantages of this approach, then the following regex should work:
<Param name="Application #"[^>]*>\s+<Param[^>]*>\s+<Param name="app_name" value="App02" />\s+(?:<Param[^>]*>\s+){2}</Param>
This relies heavily on the structure present in your example. A re-ordering of tags, introduction of additional tags or (shudder) nesting of tags will break the regex.
Seems like it would be more appropriate to use an XML reader library, but I don't know Perl enough to suggest one.
Perl's XML DOM Parser may be appropriate here.
I would suggest using one of XML parsers, but if you cannot do so, then the following quick and dirty code should do:
my ($rez) = $data =~/\<Param\s+name\s*=\s*"Application\s#"\s+value\s*=\s*"2"\>((?:.|\n)*?)^\<\/Param\>/m;
print $rez;
(assuming $data contains your xml as a single string, possibly multiline )