Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6064799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:19:11+00:00 2026-05-23T09:19:11+00:00

I want to introduce i18n in an existing application. As a first step, I

  • 0

I want to introduce i18n in an existing application. As a first step, I need to replace the string literals with tr("something").

I have created the following regex to extract the strings:

(?<!#include)"([^"\\]|\\.)*"

However, this does not work. Without the negative lookbehind, it does match strings correctly, but also quoted includes which I want to avoid. I’m not quite familiar with negative lookbehinds, I just looked them up here.

Example:

#include "hello.h"                           // should NOT match "\"hello.h\""
printf("Hello");                             // should match "\"Hello\""
cout << "hello" << "hello" << "hello";       // should match each three "\"hello\""'s

How can I do this correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:19:12+00:00Added an answer on May 23, 2026 at 9:19 am

    Ok, here is my solution (sort of):

    First, I could not do it in Qt Creator, its regex capabilities seem to be not so good at the moment. So I used vim.

    I opened all the affected files as vim buffers, then recorded the following macro:

    qa:%s/\v(#include\s+)@<!"([^"]*)"/tr(\0)/g<CR>:bn<CR>q
    

    This does the following:

    qa                                       // start recording into register "a"
    %s/\v(#include\s+)@<!"([^"]*)"/tr(\0)/g  // search and replace as specified
    <CR>                                     // (hit enter)
    :bn                                      // jump to the next buffer
    <CR>                                     // (hit enter)
    q                                        // end recording macro
    

    The regex is vim-regex with \v that makes more natural (less escaping). In short, it uses a negative lookbehind as I originally wanted, with a slightly different syntax.

    Now, I only had to run this macro for as many buffers I had open (in command mode):

    78@a
    

    The problem (and this is why it’s only a “sort of” solution) is that whenever vim encounters a buffer where the regex fails (i.e. no string literals in the file) it stops repeating the macro. I couldn’t find out how to fix that. Fortunately I had only a few files like that, so I could get away with manually re-running the above command to start repeating the macro again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Phonegap 1.3 application. I want to introduce some twitter integration for
I want to introduce a variable [i] into a string in Python. For example
I have a UIWebView i want to introduce functionality of content(may be text or
My emails will need to be HTML anyway and I don't want to introduce
HEllo, I have a site where I want to introduce reply user functionality. How
I have a client -> service -> server, architecture and I want to introduce
I am using a gwt based application and I want to introduce web service
I want to introduce Unit Testing to some colleagues that have no or little
First, I am sorry for this rough question, but I don't want to introduce
I want to introduce a cache policy in my app. Basically I have made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.