Search Results

Search found 530 results on 22 pages for 'regexp'.

Page 9/22 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • PCRE multi line matche problem

    - by Simone Margaritelli
    Hi guys, i have this C++ program (actually it's just a snippet) : #include <iostream> #include <pcre.h> #include <string> using namespace std; int main(){ string pattern = "<a\\s+href\\s*=\\s*\"([^\"]+)\"", html = "<html>\n" "<body>\n" "<a href=\"example_link_1\"/>\n" "<a href=\"example_link_2\"/>\n" "<a href=\"example_link_3\"/>\n" "</body>\n" "</html>"; int i, ccount, rc, *offsets, eoffset; const char *error; pcre *compiled; compiled = pcre_compile( pattern.c_str(), PCRE_CASELESS | PCRE_MULTILINE, &error, &eoffset, 0 ); if( !compiled ){ cerr << "Error compiling the regexp!!" << endl; return 0; } rc = pcre_fullinfo( compiled, 0, PCRE_INFO_CAPTURECOUNT, &ccount ); offsets = new int[ 3 * (ccount + 1) ]; rc = pcre_exec( compiled, 0, html.c_str(), html.length(), 0, 0, offsets, 3 * (ccount + 1) ); if( rc >= 0 ){ for( i = 1; i < rc; ++i ){ cout << "Match : " << html.substr( offsets[2*i], offsets[2*i+1] - offsets[2*i] ) << endl; } } else{ cout << "Sorry, no matches!" << endl; } delete [] offsets; return 0; } As you can see, i'm trying to match html links inside a buffer with the given regular expression (the \\s is \s escaped for C/C++ strings). But, even if in the buffer there are 3 links and the regexp is compiled with the PCRE_CASELESS and PCRE_MULTILINE flags, i match only one element : Match : example_link_1 Note: I start the loop fro index 1 because the pcre library returns the string that matched (not the match itself) as the first element, and the matches follows. What's wrong with this code? The regexp itself i think it's correct (tried in PHP for instance).

    Read the article

  • Simple JQuery Validator addMethod not working

    - by tehaaron
    Updated question on the bottom I am trying to validate a super simple form. Eventually the username will be compared to a RegExp statement and the same will go for the password. However right now I am just trying to learn the Validator addMethod format. I currently have this script: JQuery.validator.addMethod( "legalName", function(value, element) { if (element.value == "bob") { return false; } else return true; }, "Use a valid username." ); $(document).ready(function() { $("#form1").validate({ rules: { username: { legalName: true } }, }); }); Which if I am not mistaken should return false and respond with "Use a valid username." if I were to put "bob" into the form. However, it is simply submitting it. I am linking to JQuery BEFORE Validator in the header like instructed. My uber simple form looks like this: <form id="form1" method="post" action=""> <div class="form-row"><span class="label">Username *</span><input type="text" name="username" /></div> <div class="form-row"><input class="submit" type="submit" value="Submit"></div> </form> Finally how would I go about restructing the addMethod function to return true if and false at the else stage while keeping the message alert for a false return? (ignore this last part if you don't understand what I was trying to say :) ) Thanks in advance. Thank to everyone who pointed out my JQuery - jQuery typo. New Ideally, I am trying to turn this into a simple login form (username/password). It is for demonstration only so it wont have a database attached or anything, just some simple js validations. I am looking to make the username validate for <48 characters, only english letters and numbers, no special characters. I thought a whitelist would be easiest so I had something like this: ^[a-zA-Z0-9]*${1,48} but I am not sure if that is proper JS RegExp (it varies from Ruby RegExp if I am not mistaken?...Usually I use rubular.com). Password will be similar but require some upper/lowercase and numbers. I believe I need to make another $.validator.addMethod for legalPassword that will look very similar.

    Read the article

  • git-svn on subset of large svn repo

    - by an146
    repo layout: a/1 a/2 a/3 ... b/1 b/2 ... c/1 c/2 ... git-svn works perfect for me if I work on 1 svn repo subdir. But right now I'm facing the need to work on several subdirs (like, a/1, a/2, and b/1), and there's much shit in repo besides them. I've managed to write a regexp for this, but git-svn with --ignore-paths seems to check each file's name against this regexp, instead of skipping entire folders, so it's too slow. /* Probably I should file a bug report about this */ So -- any ideas of handling this? If some Mercurial svn agent can do selective clones, it's OK too, but I'd better stick with git. My another idea was some selective svn proxy, but I haven't succeeded in googling anything like that. Thanks!

    Read the article

  • Match d-M-Y with javascript regex how?

    - by bakerjr
    Hi, my date formatting in PHP is d-M-Y and I'm trying to match the dates with a javascript regex: s.match(new RegExp(/^(\d{1,2})(\-)(\w{3})(\-)(\d{4})$/)) To be used with the jQuery plugin, tablesorter. The problem is it's not working and I'm wondering why not. I tried removing the dashes in my date() formatting (d M Y) and tried the ff and it worked: s.match(new RegExp(/^\d{1,2}[ ]\w{3}[ ]\d{4}$/)); My question is what is the correct regex if I'm using dashes on PHP's date() i.e. d-M-Y? Thanks!

    Read the article

  • Match beginning of words in Mysql for UTF8 strings

    - by ankimal
    Hi, I m trying to match beignning of words in a mysql column that stores strings as varchar. Unfortunately, REGEXP does not seem to work for UTF-8 strings as mentioned here So, select * from names where name REGEXP '[[:<:]]Aandre'; does not work if I have name like Foobar Aándreas However, select * from names where name like '%andre%' matches the row I need but does not guarantee beginning of words matches. Is it better to do the like and filter it out on the application side ? Any other solutions?

    Read the article

  • Codeigniter Routes for filename with extension

    - by thehuby
    I am using codeigniter and its routes system successfully with some lovely regexp, however I have come unstuck on what should be an easy peasy thing in the system. I want to include a bunch of search engine related files (for Google webmaster etc.) plus the robots.txt file, all in a controller. So, I have create the controller and updated the routes file and don't seem to be able to get it working with these files. Here's a snip from my routes file: $route['robots\.txt|LiveSearchSiteAuth\.xml'] = 'search_controller/files'; Within the function I use the URI helper to figure out which content to show. Now I can't get this to match, which points to my regexp being wrong. I'm sure this is a really obvious one but its late and my caffeine tank is empty :)

    Read the article

  • Fancybox iframe says that my YouTube href is undefined

    - by user369732
    Here is my HTML: <a class="video iframe" href="http://www.youtube.com/watch?v=Psk2Pq03rv0">Arbitrary text</a> Here is the Fancybox javascript: $("a.video").fancybox({ 'padding' : 0, 'autoScale' : false, 'title' : this.title, 'overlayOpacity' : '.6', 'overlayColor' : '#333', 'transitionIn' : 'none', 'transitionOut' : 'none', 'centerOnScroll' : false, 'showCloseButton' : true, 'hideOnOverlayClick': false, 'href' : this.href.replace(new RegExp("watch\\?v=", "i"), "v/"), 'type' : 'swf', 'swf' : { 'wmode': 'transparent', 'allowfullscreen': 'true' } }); Firebug Console says: this.href is undefined 'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'), As a result, clicking this link takes the user to YouTube and does not trigger Fancybox. Any advice?

    Read the article

  • Filtering out emoticons using sed

    - by user349222
    Hello, I have a grep expression using cygwin grep on Win. grep -a "\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u" all_fbs.txt > rockon_fbs.txt Once I identify the emoticon class, however, I want to strip them out of the data. However, the same regexp above within a sed results in a syntax error (yes, I realize I could use /d instead of //g, but this doesn't make a difference, I still get the error.) sed "s/\(\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u\)*//g" The full line is: grep -a "\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u" all_fbs.txt | sed "s/\(\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u\)*//g" | sed "s/^/ROCKON\t/" > rockon_fbs.txt The result is: sed: -e expression #1, char 14: unknown option to `s' I know it's coming from the sed regexp I'm asking about it b/c if I remove that portion of the full line, then I get no error (but, of course, the emoticons are not filtered out). Thanks in advance, Steve

    Read the article

  • Strange JavaScript Regular Expression Behavior

    - by Kiwi
    I'm getting different behavior from a regular expression in JavaScript depending on whether or not I declare it using literal syntax. Using a extremely simple test HTML file: <html> <head> <script type="text/javascript"> var s = '3'; var regex1 = /\d/; var regex2 = new RegExp('\d'); alert(s.search(regex1)); // 0 (matches) alert(s.search(regex2)); // -1 (does not match) </script> </head> <body></body> </html> The regular expression declared with literal syntax (/\d/) works correctly, while the other (new RegExp('\d')) does not. Why on earth is this happening? I'm using Google Chrome 5.0.375.70 on Windows Vista Home Premium, if that's at all helpful.

    Read the article

  • How to get everything in the string, but a particular pattern

    - by José Leal
    Yet another regexp question: I have a string as the following, "This is a string, and I have a priority !1" So I want to build a regexp that extracts my priority, which is this number 1 preceded by the "!". To extract it is very easy, "!([1-4])". But now I want to extract the text, leaving it out! How can I do that? DETAIL: The !1 can be anywhere in the string, so this is also perfectly fine: "This is a string, !1 and I have a priority" Thanks! UPDATE: I'm using scala

    Read the article

  • How can I load a sql "dump" file into sql alchemy

    - by JudoWill
    I have a large sql dump file ... with multiple CREATE TABLE and INSERT INTO statements. Is there any way to load these all into a SQLAlchemy sqlite database at once. I plan to use the introspected ORM from sqlsoup after I've created the tables. However, when I use the engine.execute() method it complains: sqlite3.Warning: You can only execute one statement at a time. Is there a way to work around this issue. Perhaps splitting the file with a regexp or some kind of parser, but I don't know enough SQL to get all of the cases for the regexp. Any help would be greatly appreciated. Will EDIT: Since this seems important ... The dump file was created with a MySQL database and so it has quite a few commands/syntax that sqlite3 does not understand correctly.

    Read the article

  • mercurial setup for Visual Studio 2008 projects

    - by Johannes
    What is a good setup for .hgignore file when working with Visual Studio 2008? I mostly develop on my own, only occasionly I clone the repository for somebody else to work on it. I'm thinking about obj folders, .suo, .sln, .user files etc.. Can they just be included or are there file I shouldn't include? Thanks! p.s.: at the moment I do the following : ignore all .pdb files and all obj folders. # regexp syntax. syntax: glob *.pdb syntax: regexp /obj/

    Read the article

  • parsing/matching string occurrence in C

    - by David
    I have the following string: const char *str = "\"This is just some random text\" 130 28194 \"Some other string\" \"String 3\"" I would like to get the the integer 28194 of course the integer varies, so I can't do strstr("20194"). So I was wondering what would be a good way to get that part of the string? I was thinking to use #include <regex.h> which I already have a procedure to match regexp's but not sure how the regexp in C will look like using the POSIX style notation. [:alpha:]+[:digit:] and if performance will be an issue. Or will it be better using strchr,strstr? Any ideas will be appreciate it

    Read the article

  • Proper Regex to find and replace escaped UTF-8 strings

    - by Piet Binnenbocht
    (edited) I am reading a JSON file that includes some UTF-8 characters that are encoded like this: "\uf36b". I am trying to write a RegExp to convert this to an HTML entity that looks like "&#x1F36B;". This displays the character correctly in my html page. I haven't been able to correctly display the character that should be associated with "\uf36b", especially when in a longer sentence that also includes other text. How can I write a regexp that replaces strings like "\uf4d6" and "\uf36b" but leaves other text alone? Example: var str = "I need \uf36b #chocolate"; This should be converted to: I need &#x1F36B; #chocolate;

    Read the article

  • Search pattern in string using regex in obj-c

    - by manileo86
    I'm working on a string pattern match algorithm. I use NSRegularExpression for finding the matches. For ex: I've to find all words starting with '#' in a string.. Currently I use the following regex function: static NSRegularExpression *_searchTagRegularExpression; static inline NSRegularExpression * SearchTagRegularExpression() { if (!_searchTagRegularExpression) { _searchTagRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"(?<!\\w)#([\\w\\._-]+)? options:NSRegularExpressionCaseInsensitive error:nil]; } return _searchTagRegularExpression; } and I use it as below: NSRegularExpression *regexp = SearchTagRegularExpression(); [regexp enumerateMatchesInString:searchString options:0 range:stringRange usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { // comes here for every match with range }]; This works properly. But i just want to know if this is the best way. suggest if there's any better alternative...

    Read the article

  • preg_match and long strings

    - by aleluja
    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.

    Read the article

  • How to define a function which repeats itself when passed an argument

    - by ~unutbu
    Is there an easy way to define a function which repeats itself when passed an argument? For example, I've defined the following function (defun swap-sign () (interactive) (search-forward-regexp "[+-]") (if (equal (match-string 0) "-") (replace-match "+") (replace-match "-")) ) I'd like C-u swap-sign to call swap-sign four times. I've tried (defun swap-sign (&optional num) (interactive) (let ((counter 0) (num (if num (string-to-number num) 0))) (while (<= counter num) (search-forward-regexp "[+-]") (if (equal (match-string 0) "-") (replace-match "+") (replace-match "-")) (setq counter (1+ counter))))) but C-u swap-sign still only runs swap-sign (or perhaps more precisely, the body of the while-loop) once. I'm guessing it is because if num is not the right way to test if num is an empty string. Am I on the right track, or is there a better/easier way to extend swap-sign?

    Read the article

  • Erroneous Matches with Regular Expression

    - by Ballsacian1
    $regexp = '/(?:<input\stype="hidden"\sname="){1}([a-zA-Z0-9]*)(?:"\svalue="1"\s\/>)/'; $response = '<input type="hidden" name="7d37dddd0eb2c85b8d394ef36b35f54f" value="1" />'; preg_match($regexp, $response, $matches); echo $matches[1]; // Outputs: 7d37dddd0eb2c85b8d394ef36b35f54f So I'm using this regular expression to search for an authentication token on a webpage implementing Joomla in order to preform a scripted login. I've got all this working but am wondering what is wrong with my regular expression as it always returns 2 items. Array ( [0] => [1] => 7d37dddd0eb2c85b8d394ef36b35f54f) Also the name of the input I'm checking for changes every page load both in length and name.

    Read the article

  • Rails - Dynamic cookie domains using Rack

    - by Tim B.
    I'm fairly new to Rails and Rack, but this guy had a seemingly straightforward write-up about using Rack to implement dynamic session domain middleware. The code looks good to and I've implemented it here on my local machine, but I'm still not able to transcend top level domains on a single login. Here's the middleware code: class SetCookieDomain def initialize(app, default_domain) @app = app @default_domain = default_domain end def call(env) host = env["HTTP_HOST"].split(':').first env["rack.session.options"][:domain] = custom_domain?(host) ? ".#{host}" : "#{@default_domain}" @app.call(env) end def custom_domain?(host) domain = @default_domain.sub(/^\./, '') host !~ Regexp.new("#{domain}$", Regexp::IGNORECASE) end end And then in environment.db: config.load_paths += %W(#{RAILS_ROOT}/app/middlewares) Lastly in production.db (and development.db): config.middleware.use "SetCookieDomain", ".example.org" Any help is greatly appreciated. EDIT: I'm running Rails 2.3.3 and Rack 1.0

    Read the article

  • How do I specify the regular expression to disable the use of underscores after the '@' sign in php for email validation?

    - by Qlidnaque
    Currently the following email in the script validates even though there are no underscores indicated in the second part of the regular expression validation after the '@' sign. How do I make underscores invalid in the second part of the email? <?php $email = 'firstname.lastname@a_aa.bbb.co_m'; $regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9]+([.][A-z0-9]+)*[.][A-z]{2,4}$/"; if (preg_match($regexp, $email)) { echo "Email address is valid."; } else { echo "Email address is <u>not</u> valid."; } ?>

    Read the article

  • Using user editable image URL in application. Security issues.

    - by sharas
    Hi there. I am writing an application where users are required to show their photo, however as my server resources are very limited I can not let them upload it to the server. So I have three major questions: 1. How to properly validate photo URL? At least I can validate with regexp, however I need to check for file ending: `validates_format_of :photo_url, :with => URI::regexp(%w(http https))` 2. Security issues? XSS? Even I validate the picture at the moment of creation, hacker can replace image with malicious stuff anytime. 3. Maybe there are free asset stores with API?

    Read the article

  • How to use jQuery to generate 2 new associated objects in a nested form?

    - by mind.blank
    I have a model called Pair, which has_many :questions, and each Question has_one :answer. I've been following this railscast on creating nested forms, however I want to generate both a Question field and it's Answer field when clicking on an "Add Question" link. After following the railscast this is what I have: ..javascripts/common.js.coffee: window.remove_fields = (link)-> $(link).closest(".question_remove").remove() window.add_fields = (link, association, content)-> new_id = new Date().getTime() regexp = new RegExp("new_" + association, "g") $(link).before(content.replace(regexp, new_id)) application_helper.rb: def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.simple_fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end link_to_function(name, "window.add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")", class: "btn btn-inverse") end views/pairs/_form.html.erb: <%= simple_form_for(@pair) do |f| %> <div class="row"> <div class="well span4"> <%= f.input :sys_heading, label: "System Heading", placeholder: "required", input_html: { class: "span4" } %> <%= f.input :heading, label: "User Heading", input_html: { class: "span4" } %> <%= f.input :instructions, as: :text, input_html: { class: "span4 input_text" } %> </div> </div> <%= f.simple_fields_for :questions do |builder| %> <%= render 'question_fields', f: builder %> <% end %> <%= link_to_add_fields "<i class='icon-plus icon-white'></i> Add Another Question".html_safe, f, :questions %> <%= f.button :submit, "Save Pair", class: "btn btn-success" %> <% end %> _question_fields.html.erb partial: <div class="question_remove"> <div class="row"> <div class="well span4"> <%= f.input :text, label: "Question", input_html: { class: "span4" }, placeholder: "your question...?" %> <%= f.simple_fields_for :answer do |builder| %> <%= render 'answer_fields', f: builder %> <% end %> </div> </div> </div> _answer_fields.html.erb partial: <%= f.input :text, label: "Answer", input_html: { class: "span4" }, placeholder: "your answer" %> <%= link_to_function "remove", "remove_fields(this)", class: "float-right" %> I'm especially confused by the reflect_on_association part, for example how does calling .new there create an association? I usually need to use .build Also for a has_one I use .build_answer rather than answers.build - so what does this mean for the jQuery part?

    Read the article

  • Zabbix Log Monitoring - Duplicate alerts

    - by ArunS
    I am configured Zabbix to monitor my Jboss Server logs for Erros and exclude some know errors. This setup is working with one issue. Zabbix will send me alerts when there is a new "ERROR" entry in the log file. But sometimes I get multiple alerts for the same event. For example, I got 5 alerts with the same time stamp "2012-06-25 07:55:56,864 ERROR". The duplicate alerts count is not constant, sometimes I get 2 sometimes 5 or 11. I checked the Monitoring Latest data in the GUI, and found that there is no duplicate entries. I have given my configuration of the log monitoring below. I am using latest version of zabbix server(2.0) Item configuration: Description: Server Error Monitoring. Key: log["/SERVER/jboss/jboss-5/server/ps/log/server.log","ERROR",UTF-8,200,skip] Type: Zabbix Agent (Active) Type of information: Log Interval :30 Trigger configuration: Description: Found Error in Server Log. Expression: (({SERVER Error Monitoring - PS:log["/SERVER/jboss/jboss-5/server/ps/log/server.log","ERROR",UTF-8,200,skip].regexp("can not execute")})=0) & (({SERVER Error Monitoring - PS:log["/SERVER/jboss/jboss-5/server/ps/log/server.log","ERROR",UTF-8,200,skip].regexp("Unexpected redirect")})=0) Event generation: Normal + Multiple TRUE events Action configuration: Name: alert mail Event source: Trigger Enable escalations: Uncheck Default subject/message: Default Recovery message: Uncheck Action conditions: Trigger value = PROBLEM Action operations: Send message to User "Admin" Please help me fixing this issue.

    Read the article

  • How to list rpm packages/subpackages sorted by total size

    - by smci
    Looking for an easy way to postprocess rpm -q output so it reports the total size of all subpackages matching a regexp, e.g. see the aspell* example below. (Short of scripting it with Python/PERL/awk, which is the next step) (Motivation: I'm trying to remove a few Gb of unnecessary packages from a CentOS install, so I'm trying to track down things that are a) large b) unnecessary and c) not dependencies of anything useful like gnome. Ultimately I want to pipe the ouput through sort -n to what the space hogs are, before doing rpm -e) My reporting command looks like [1]: cat unwanted | xargs rpm -q --qf '%9.{size} %{name}\n' > unwanted.size and here's just one example where I'd like to see rpm's total for all aspell* subpackages: root# rpm -q --qf '%9.{size} %{name}\n' `rpm -qa | grep aspell` 1040974 aspell 16417158 aspell-es 4862676 aspell-sv 4334067 aspell-en 23329116 aspell-fr 13075210 aspell-de 39342410 aspell-it 8655094 aspell-ca 62267635 aspell-cs 16714477 aspell-da 17579484 aspell-el 10625591 aspell-no 60719347 aspell-pl 12907088 aspell-pt 8007946 aspell-nl 9425163 aspell-cy Three extra nice-to-have things: list the dependencies/depending packages of each group (so I can figure out the uninstall order) Also, if you could group them by package group, that would be totally neat. Human-readable size units like 'M'/'G' (like ls -h does). Can be done with regexp and rounding on the size field. Footnote: I'm surprised up2date and yum don't add this sort of intelligence. Ideally you would want to see a tree of group-package-subpackage, with rolled-up sizes. Footnote 2: I see yum erase aspell* does actually produce this summary - but not in a query command. [1] where unwanted.txt is a textfile of unnecessary packages obtained by diffing the output of: yum list installed | sed -e 's/\..*//g' > installed.txt diff --suppress-common-lines centos4_minimal.txt installed.txt | grep '>' and centos4_minimal.txt came from the Google doc given by that helpful blogger.

    Read the article

  • Best grep-like tool

    - by e-satis
    I do in file search a lot, and used to love grep. Then I learn the existence of egrep, so I switched to benefit from the advanced regexp. Then I discovered the Eclipse search tool. Much easier to use that grep. Then I found ack : fast, easy, powerful. And now I use grin, which is smooth for pythonistas. I know there is also a couple of this kind of tools with a GUI. So what tool do you use, and why do you think it's the best. Practical features generally are : fast to fire and use; speedy processing; automatically ignore useless files; colored output; output lines, filename, context; allow complex regexp; allow a custom filtering and ouput; GUI + command line intergation; let you open an editor from the result set. There are some related posts on SO : http://stackoverflow.com/questions/87350/what-are-good-grep-tool-for-windows http://stackoverflow.com/questions/981601/colorized-grep-viewing-the-entire-file-with-highlighting http://stackoverflow.com/questions/1028107/is-there-some-unix-util-that-will-allow-me-to-grep-multiple-files-with-little-type http://stackoverflow.com/questions/1027906/unix-find-grep-syntax-vs-awk

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >